-
Notifications
You must be signed in to change notification settings - Fork 1k
Closed
Description
Add data structure example i.e. Nested list, Counter, Lambda function, Sorting, deque, heap.
While solving any kind of problem, the data structure is important. I want to contribute to this repository by adding examples on the above topics with proper documentation.
Basically, each of the topics will contain motivation, use case, example, dos, and don't-s.
Here's an example:
Initializing a nested list in this format [ [ v ] * n ] * n is not always a good idea.
Look at the snippet below:
>>> a = [ [0] * 3 ] * 3
>>> a
[[0, 0, 0], [0, 0, 0], [0, 0, 0]]
>>> a[0][0]=1
>>> a
[[1, 0, 0], [1, 0, 0], [1, 0, 0]]
So all of the 0th element of the lists got changed.
It's because * is copying the address of the object (list).
Like this
Metadata
Metadata
Assignees
Labels
No labels