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

Advanced queues #2988

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
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 @@ -68,6 +68,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 - Advanced Queues - Move single-line commands to a single line, update indentation in codeblocks from 4 to 2 spaces](https://github.com/enkidevs/curriculum/pull/2988)
- [Python - Playing With Time - Move single-line commands to a single line, update indentation in codeblocks from 4 to 2 spaces](https://github.com/enkidevs/curriculum/pull/3007)
- [Python - Deep Into Collections - Move single-line commands to a single line, update indentation in codeblocks from 4 to 2 spaces](https://github.com/enkidevs/curriculum/pull/2997)
- [Python - Python Functions - Move single-line commands to a single line, update indentation in codeblocks from 4 to 2 spaces](https://github.com/enkidevs/curriculum/pull/3008)
Expand Down
24 changes: 12 additions & 12 deletions python/python-core/advanced-queues/prioritize-your-queue.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,18 +31,18 @@ It uses the sort method `sort` in order to decide what to retrieve from it first
import queue

class Enki(object):
def __init__(self, priority):
self.priority = priority
return
def __lt__(self, other):
return self.priority < other.priority
def __init__(self, priority):
self.priority = priority
return
def __lt__(self, other):
return self.priority < other.priority

q = queue.PriorityQueue()
q.put(Enki(55))
q.put(Enki(3))
q.put(Enki(100))
while not q.empty():
print(q.get().priority)
print(q.get().priority)
# output is 3 / 55 / 100
```

Expand All @@ -52,18 +52,18 @@ If we want to reverse the sorting order (greatest priority first), we would have

```python
class Enki(object):
def __init__(self, priority):
self.priority = priority
return
def __lt__(self, other):
return self.priority > other.priority
def __init__(self, priority):
self.priority = priority
return
def __lt__(self, other):
return self.priority > other.priority

q = queue.PriorityQueue()
q.put(Enki(55))
q.put(Enki(3))
q.put(Enki(100))
while not q.empty():
print(q.get().priority)
print(q.get().priority)
# output is 100 / 55 / 3
```

Expand Down
3 changes: 1 addition & 2 deletions python/python-core/advanced-queues/queue-s-and-threads.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,7 @@ Complete the code snippet:
q = Queue()
??? = 3 # declare 3 threads
for i in range(num_threads):
worker = ??? \
(target=enki, args=(q,))
worker = ???(target=enki, args=(q,))
worker.setDaemon(True)
worker.start()
```
Expand Down