-
Notifications
You must be signed in to change notification settings - Fork 8
Lecture "Organising information: ordered structures", exercise 3 #14
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
Comments
''' finally printing my_queue will look like |
|
Finally |
my_queue = deque(["Draco", "Harry", "Hermione", "Ron", "Severus"])- initial state of the queue By executing my_queue.popleft() - we remove "Draco" from the queue, rule of the queue FIFO - current state of the queue ["Harry", "Hermione", "Ron", "Severus"]) By my_queue.append("Voldemort") - we add "Voldemort" at the back of the queue, and now it looks like this -current state of the queue -["Harry", "Hermione", "Ron", "Severus", Voldemort"] Next we execute once again my_queue.popleft() - we remove the 1st element on the left side, which in this case is "Harry" So the final look of the queue should be ["Hermione", "Ron", "Severus", Voldemort"] |
|
So; after the execution of each of the following operations, my_queue is ( ['Hermione', 'Ron', 'Severus', 'Voldemort'] ) . |
my_queue=deque(["Draco", "Harry", "Hermione", "Ron", "Severus"]) my_queue.popleft() my_queue.append("Voldemort") my_queue.popleft() |
1 from collections import deque In line 3, "Draco" is removed from the queue. The queue now contains "Harry", "Hermione", "Ron", and "Severus". |
my_queue = deque(["Draco", "Harry", "Hermione", "Ron", "Severus"])
|
|
my_queue=deque(["Draco", "Harry", "Hermione", "Ron", "Severus"]) my_queue.popleft() #it removes the first inserted element |
harry_potter_queue = deque(["Draco", "Harry", "Hermione", "Ron", "Severus"])
|
my_queue = deque(["Draco", "Harry", "Hermione", "Ron", "Severus"]) my_queue.popleft () # Draco is remove, because in this case the first it’s the first out My_queque.append (“Voldemort”) #add Voldermort at the end of the queue my_queue.popleft () # Harry is remove, because in this case the first it’s the first out |
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 of my_queue after the execution of each of the following operations: my_queue.popleft(), my_queue.append("Voldemort"), my_queue.popleft(). Let's first create the queue: my_queue = deque() print(my_queue) Result: ['Draco', 'Harry', 'Hermione', 'Ron', 'Severus'] Since in a queue, the first element added is even the first that is deleted (FIFO strategy): |
my_queue = deque(["Draco", "Harry", "Hermione", "Ron", "Severus"]) my_queue.popleft() my_queue.append("Voldemort") my_queue.popleft() Output would be [“Hermione", "Ron", "Severus", Voldemort"] |
characters_queue = deque() |
my_hp_queue = deque() print (my_hp_queue) Output ["Draco", "Harry", "Hermione", "Ron", "Severus"] my_hp_queue.popleft() # removes the first element added print (my_hp_queue) Output [ "Hermione", "Ron", "Severus", "Voldemort"] |
from collections import deque my_queue.popleft() my_queue.append("Voldemort") my_queue.popleft() Here the results obtained after every 'print' stage: deque(['Draco', 'Harry', 'Hermione', 'Ron', 'Severus']) |
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: