Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More on lists #3005

Merged
merged 5 commits into from
Jan 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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