comp-think / 2019-2020

The GitHub repository containing all the material related to the Computational Thinking and Programming course of the Digital Humanities and Digital Knowledge degree at the University of Bologna (a.a. 2019/2020).
Other
12 stars 3 forks source link

Lecture "Organising information: ordered structures", exercise 2 #13

Open essepuntato opened 4 years ago

essepuntato commented 4 years ago

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").

arcangelo7 commented 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'
Vince2992 commented 4 years ago

Ex2

arcangelo7 commented 4 years ago

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

Vince2992 commented 4 years ago

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

ariele-santello commented 4 years ago

Schermata 2019-10-28 alle 18 58 31

noreanystrom commented 4 years ago

image

elisasilvad commented 4 years ago

Excercise 4 2

arimuti commented 4 years ago

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

morinigiu commented 4 years ago
Schermata 2019-10-30 alle 00 09 33
FrancescoFernicola commented 4 years ago

ex2_28_10_2019

Although I have to admit, I wish I had @Vince2992 's variable naming skills! Chapeau--

ariannamorettj commented 4 years ago

image

aschimmenti commented 4 years ago

Pop pop append

deque(['Draco', 'Harry', 'Hermione', 'Voldemort'])