Skip to content

Commit

Permalink
Merge pull request #3005 from enkidevs/more-on-lists
Browse files Browse the repository at this point in the history
More on lists
  • Loading branch information
Stefan-Stojanovic authored Jan 14, 2022
2 parents 8b972b4 + 0713cba commit 6146c8e
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 11 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ Types of change:
### Changed
- [Html - Link Relative Paths - Change part of PQ as it wasn't worder properly](https://github.com/enkidevs/curriculum/pull/2985)
- [Python - Format Text Paragraphs With Textwrap - Make the fill method more clear](https://github.com/enkidevs/curriculum/pull/2981)
- [Python - More On Lists - Move single-line commands to a single line, update indentation in codeblocks from 4 to 2 spaces](https://github.com/enkidevs/curriculum/pull/3005)
- [Python - Classes I - Move single-line commands to a single line, update indentation in codeblocks from 4 to 2 spaces](https://github.com/enkidevs/curriculum/pull/2992)
- [Python - Looping - Move single-line commands to a single line, update indentation in codeblocks from 4 to 2 spaces](https://github.com/enkidevs/curriculum/pull/3000)
- [Python - Meet Python - Move single-line commands to a single line, update indentation in codeblocks from 4 to 2 spaces](https://github.com/enkidevs/curriculum/pull/3003)
Expand Down
2 changes: 1 addition & 1 deletion python/python-core/more-on-lists/lists-vs-dictionaries.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ dict = {
}
```

Because elements stored in **lists** can be accessed using **indices**, the retrieving of an element will be done in `O(n)` in the worst case scenario. When using **dictionaries**, indices are replaced by **keys** (hashable types). This means that retrieving a certain element would be done in `O(1)` as we can find each **value** associated to each **key** directly.
Because elements stored in **lists** can be accessed using **indices**, the retrieving of an element will be done in `O(n)` in the worst-case scenario. When using **dictionaries**, indices are replaced by **keys** (hashable types). This means that retrieving a certain element would be done in `O(1)` as we can find each **value** associated to each **key** directly.

Let's see an example:

Expand Down
20 changes: 10 additions & 10 deletions python/python-core/more-on-lists/using-lists-as-queues.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,20 +37,20 @@ Let's define a **queue** class now:

```py
class Queue:
def __init__(self):
self.items = []
def __init__(self):
self.items = []

def isEmpty(self):
return self.items == []
def isEmpty(self):
return self.items == []

def enqueue(self, item):
self.items.insert(0,item)
def enqueue(self, item):
self.items.insert(0,item)

def dequeue(self):
return self.items.pop()
def dequeue(self):
return self.items.pop()

def size(self):
return len(self.items)
def size(self):
return len(self.items)
```

> 💡 Instead of `size` you can use `__len__`. It will allow you to use `len(myQueue)` instead of `myQueue.size()`. Check the *Learn More* section for a playground link. We've prepared both queue classes in there so you can test them out and decide which one you want to use.
Expand Down

0 comments on commit 6146c8e

Please sign in to comment.