-
Notifications
You must be signed in to change notification settings - Fork 5
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
Lecture "Organising information: ordered structures", exercise 3 #15
Comments
harry_potter_queue = deque ()
harry_potter_queue.append("Draco")
harry_potter_queue.append("Harry")
harry_potter_queue.append("Hermione")
harry_potter_queue.append("Ron")
harry_potter_queue.append("Severus")
harry_potter_queue.popleft()
# "Draco" was returned and then removed from the left-most part of the queue, now the queue is ["Harry", "Hermione", "Ron", "Severus"]
harry_potter_queue.append("Voldemort")
# "Voldemort" was added to the end of the queue, now the queue is ["Harry", "Hermione", "Ron", "Severus", "Voldemort"]
harry_potter_queue.popleft()
# "Harry" was returned and then removed from the left_most part of the queue, now the queue is ["Hermione", "Ron", "Severus", "Voldemort"] |
by calling
|
from collections import deque my_queue = deque(["Draco", "Harry", "Hermione", "Ron", "Severus"]) my_queue.popleft() # deque(['Harry', 'Hermione', 'Ron', 'Severus']) <- "Draco" gone from the beginning of the queue |
Friends_queue = deque() "Voldemort" has been added to the queueprint(Friends_queue) |
|
from collections import deque
my_queue = deque(["Harry", "Draco", "Hermione", "Ron", "Severus"])
my_queue.popleft()
my_queue.append("Voldemort")
my_queue.popleft()
print(my_queue) |
from collections import deque my_queue = deque () print(my_queue) my_queue.popleft() my_queue.append("Voldemort") my_queue.popleft() OUTPUT(s): deque(['Harry', 'Draco', 'Hermione', 'Ron', 'Severus']) |
|
|
HP_queue = deque() output: deque(['Hermione', 'Ron', 'Severus', 'Voldemort']) |
|
Consider to have a queue obtained by processing, one by one, the elements included in the list of the first exercise, i.e.
my_queue = deque(["Draco", "Harry", "Hermione", "Ron", "Severus"])
. Describe the status ofmy_queue
after the execution of each of the following operations:my_queue.popleft()
,my_queue.append("Voldemort")
,my_queue.popleft()
.The text was updated successfully, but these errors were encountered: