-
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 2 #14
Comments
harry_potter_stack = deque ()
harry_potter_stack.append("Draco")
harry_potter_stack.append("Harry")
harry_potter_stack.append("Hermione")
harry_potter_stack.append("Ron")
harry_potter_stack.append("Severus")
harry_potter_stack.pop()
# "Severus" was returned and then removed from the top of the stack, now the stack is ["Draco", "Harry", "Hermione", "Ron"]
harry_potter_stack.pop()
# "Ron" was returned and then removed from the top of the stack, now the stack is ["Draco", "Harry", "Hermione"]
harry_potter_stack.append("Voldemort")
# "Voldemort" was added to the top of the stack, now the stack is ["Draco", "Harry", "Hermione", "Voldemort"] |
|
from collections import deque Friends_stack = deque() |
|
from collections import deque
my_stack= deque(["Harry", "Draco", "Hermione", "Ron", "Severus"])
my_stack.pop()
my_stack.pop()
my_stack.append("Voldermort")
print(my_stack) |
from collections import deque my_stack = deque () print(my_stack) my_stack.pop() my_stack.pop() my_stack.append("Voldemort") OUTPUT(s): deque(['Harry', 'Hermione', 'Ron', 'Draco', 'Severus']) |
|
|
my_stack = deque() output: deque(['Draco', 'Harry', 'Hermione', 'Voldemort']) |
|
Consider to have a stack obtained by processing, one by one, the elements included in the list of the first exercise, i.e.
my_stack = deque(["Draco", "Harry", "Hermione", "Ron", "Severus"])
. Describe the status ofmy_stack
after the execution of each of the following operations:my_stack.pop()
,my_stack.pop()
,my_stack.append("Voldemort")
.The text was updated successfully, but these errors were encountered: