-
Notifications
You must be signed in to change notification settings - Fork 9
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 #16
Comments
The status of my_queue after all the operations is: Harry, Hermione, Ron, Severus |
After the execution of the operations the status of my_queue Will be: Harry, Hermione, Ron, Severus |
|
|
Even though not performed in a row, the two commands |
deque(['Hermione', 'Ron', 'Severus', 'Voldemort'])
|
Popleft() method removes "Draco" as it is the first item on the left of the queue, then append() method adds "Voldemort" as a new item and puts it at the rightmost side of the queue, lastly popleft() method once again removes the new first item "Harry". |
my_queue = deque(["Draco", "Harry", "Hermione", "Ron", "Severus"]) my_queue.popleft() queue becomes (["Harry", "Hermione", "Ron", "Severus"]) my_queue.append("Voldemort") queue becomes (["Harry", "Hermione", "Ron", "Severus", "Voldemort"]) my_queue.popleft() queue becomes (["Hermione", "Ron", "Severus", "Voldemort"]) |
|
from collections import deque my_queue = deque(["Draco", "Harry", "Hermione", "Ron", "Severus"]) deque(['Hermione', 'Ron', 'Severus', 'Voldemort']) |
|
from collections import deque my_queue = deque(["Draco", "Harry", "Hermione", "Ron", "Severus"]) my_queue.append("Voldemort") # Voldemort arrives my_queue.popleft() # the second to arrive now leaves |
my_queue my_queue.popleft() my_queue.append("Voldemort") my_queue.popleft() |
INPUT my_queue = Deque(["Draco", "Harry", "Hermione", "Ron", "Severus"]) my_queue.popleft() my_queue.append("Voldemort") my_queue.popleft() OUTPUT |
my_queue = deque (["Draco", "Harry", "Hermione", "Ron", "Severus"]) my_queue.popleft ( ) # it removes the first item added my_queue.append ( "Voldemort") my_queue.popleft ( ) |
from collections import deque # import statement my_queue.popleft() my_queue.append("Voldemort") my_queue.popleft() |
|
pop.left will remove "Drace" from the stack(which is being treated like a queue at this point) deque['Hermoine','Ron','Severus','Voldermort'] |
deque(['Hermione', 'Ron', 'Severus', 'Voldemort']) |
|
The status of my_queue after the execution of each operation will be my_queue = (["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: