Open essepuntato opened 4 years ago
from collections import deque
my_stack = deque(["Draco", "Harry", "Hermione", "Ron", "Severus"])
my_stack.pop()
# The stack contains 'Draco', 'Harry', 'Hermione' and 'Ron'. No 'Severus' anymore
my_stack.pop()
# The stack contains 'Draco', 'Harry' and 'Hermione'. No 'Ron' anymore
my_stack.append("Voldemort")
# The stack contains 'Draco', 'Harry', 'Hermione' and 'Voldemort'. We have added 'Voldemort'
Replying to https://github.com/comp-think/2019-2020/issues/13#issuecomment-547011611 by @Vince2992:
Finding hidden meanings in the exercises: you are doing it well
All Harry Potter characters have a strange/bad influence on me xD XD and we didn't even mention Dobby, the elf! ahahaha thanks @arcangelo7 :D :D
from collections import deque my_stack = deque(["Draco", "Harry", "Hermione", "Ron", "Severus"]) my_stack.popleft() print(my_stack) output ---> deque(['Harry', 'Hermione', 'Ron', 'Severus']) #it removes the first element on the left my_stack.pop() print(my_stack) output ---> deque(['Harry', 'Hermione', 'Ron']) #it removes the first item on the right my_stack.append("Voldemort") print(my_stack) output ---> deque(['Harry', 'Hermione', 'Ron', 'Voldemort']) #it adds "Voldemort" on the right, as last item
p.s.: sorry I mixed up the two assignments
Although I have to admit, I wish I had @Vince2992 's variable naming skills! Chapeau--
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 of my_stack after the execution of each of the following operations:my_stack.pop()
,my_stack.pop()
,my_stack.append("Voldemort")
.