Skip to content
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 #15

Open
essepuntato opened this issue Oct 24, 2021 · 25 comments
Open
Labels

Comments

@essepuntato
Copy link
Contributor

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

@giorgimariachiara
Copy link

The status of my_stack at the and of all the operations is: Draco, Harry, Hermione, Voldemort

@elizastuglik
Copy link

The status of the my_stack Will be: Draco, Harry, Hermione, Voldemort.

@sotarega
Copy link

my_stack = deque(["Draco", "Harry", "Hermione", "Ron", "Severus"])
print(my_stack)
['Draco', 'Harry', 'Hermione', 'Ron', 'Severus']

my_stack.pop()
print(my_stack)
['Draco', 'Harry', 'Hermione', 'Ron']

my_stack.pop()
print(my_stack)
['Draco', 'Harry', 'Hermione']

my_stack.append("Voldemort")
print(my_stack)
['Draco', 'Harry', 'Hermione', 'Voldemort']

@tommasobattisti
Copy link

my_stack will contain the following items:
"Draco", "Harry", "Hermione", "Voldemort".

from collections import deque
my_stack = deque(["Draco", "Harry", "Hermione", "Ron", "Severus"])
my_stack.pop()
my_stack.pop()
my_stack.append("Voldemort")
print(my_stack)

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

@ManueleVeggi
Copy link

The two commands my_stack.pop() will remove the last elements, which are 'Ron' and 'Severus. The command extend will add the 'Voldemort'at the end of the stack. The result is hence:
['Draco', 'Harry', 'Hermione', 'Voldemort']

@OrsolaMBorrini
Copy link

OrsolaMBorrini commented Oct 25, 2021

my_stack = deque(["Draco", "Harry", "Hermione", "Ron", "Severus"])
my_stack.pop()
#The status of my_stack is now ["Draco", "Harry", "Hermione", "Ron"]
my_stack.pop()
#The status of my_stack is now ["Draco", "Harry", "Hermione"]
my_stack.append("Voldemort")
#The status of my_stack is now ["Draco", "Harry", "Hermione", "Voldemort"]

@CarmenSantaniello
Copy link

my_stack = deque(["Draco", "Harry", "Hermione", "Ron", "Severus"])
my_stack.pop()

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

my_stack = deque(["Draco", "Harry", "Hermione", "Ron", "Severus"])
my_stack.pop()
my_stack.pop()

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

my_stack = deque(["Draco", "Harry", "Hermione", "Ron", "Severus"])
my_stack.pop()
my_stack.pop()
my_stack.append("Voldemort")

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

@ghasempouri1984
Copy link

from collections import deque

my_stack = deque(["Draco", "Harry", "Hermione", "Ron", "Severus"])
print(my_stack)

my_stack.pop()
print(my_stack)

my_stack.pop()
print(my_stack)

my_stack.append("Voldemort")
print(my_stack)

@angstigone
Copy link

angstigone commented Oct 25, 2021

my_stack = deque(["Draco", "Harry", "Hermione", "Ron", "Severus"])

my_stack.pop()

stack becomes (["Draco", "Harry", "Hermione", "Ron"]).

my_stack.pop()

stack becomes (["Draco", "Harry", "Hermione"]).

my_stack.append(Voldemort).

stack becomes (["Draco", "Harry", "Hermione", "Voldemort"]).

@MaddaGh
Copy link

MaddaGh commented Oct 26, 2021

stack

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

@NoraPs
Copy link

NoraPs commented Oct 26, 2021

from collections import deque
from typing import Deque

my_stack = deque (["Draco", "Harry", "Hermione", "Ron", "Severus"])
my_stack.pop()
my_stack.pop()
my_stack.append("Voldemort")
print (my_stack)

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

@francescabudel
Copy link

my_stack = deque (["Draco", "Harry","Hermione", "Ron", "Severus"])
my_stack.pop() 
my_stack.pop()
my_stack.append("Voldemort")

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

@sterenz
Copy link

sterenz commented Oct 27, 2021

from collections import deque

my_stack = deque(["Draco", "Harry", "Hermione", "Ron", "Severus"])
my_stack.pop() # remove the rightmost item
print(my_stack)
deque(['Draco', 'Harry', 'Hermione', 'Ron'])

my_stack.pop() # remove the rightmost item
print(my_stack)
deque(['Draco', 'Harry', 'Hermione'])

my_stack.append("Voldemort") # add a new entry to the right side
print(my_stack)
deque(['Draco', 'Harry', 'Hermione', 'Voldemort'])

@RebeccaJillianBeattie
Copy link

Visualising it like a stack:

my_stack
Severus
Ron
Hermione
Harry
Draco
["Draco", "Harry", "Hermione", "Ron", "Severus"]

my_stack.pop()
Ron
Hermione
Harry
Draco
["Draco", "Harry", "Hermione", "Ron"]

my_stack.pop()
Hermione
Harry
Draco
["Draco", "Harry", "Hermione"]

my_stack.append("Voldemort")
Voldemort
Hermione
Harry
Draco
["Draco", "Harry", "Hermione", "Voldemort"]

@olgagolgan
Copy link

olgagolgan commented Oct 27, 2021

image
image

@SaraVell1
Copy link

image

@AnastasiyaSopyryaeva
Copy link

INPUT
from typing import Deque
my_stack = Deque(["Draco", "Harry", "Hermione", "Ron", "Severus"])
print(my_stack)

my_stack.pop()
print(my_stack)

my_stack.pop()
print(my_stack)

my_stack.append("Voldemort")
print(my_stack)

OUTPUT
deque(['Draco', 'Harry', 'Hermione', 'Ron', 'Severus'])
deque(['Draco', 'Harry', 'Hermione', 'Ron'])
deque(['Draco', 'Harry', 'Hermione'])
deque(['Draco', 'Harry', 'Hermione', 'Voldemort'])

@martasoricetti
Copy link

The method .pop() removes the item on the top of the stack, that is the last item added in the stack ->

my_stack.pop()
print(my_stack)
deque(["Draco", "Harry", "Hermione", "Ron"])

my_stack.pop()
print(my_stack)
deque(["Draco", "Harry", "Hermione"])

The method .append() allows one to add an item on the top of the stack ->

my_stack.append("Voldemort")
print(my_stack)
deque(["Draco", "Harry", "Hermione", "Voldemort"])

@chloeppd
Copy link

Screenshot 2021-10-28 at 4 39 33 PM

@AmeliaLamargese
Copy link

my_stack = deque(["Draco", "Harry", "Hermione", "Ron", "Severus"]) 

with the execution of my_stack.pop() function, the last item will be removed,
in this case "Severus" will be deleted and returned
my_stack = ["Draco", "Harry", "Hermione", "Ron"]

after my_stack.pop() function, the last item will be removed,
in this case "Ron" will be deleted and returned
my_stack = ["Draco", "Harry", "Hermione"]

with my_stack.append("Voldemort") , "Voldemort" will be added to the stack as the last item
my_stack = ["Draco", "Harry", "Hermione", "Voldemort"]

@ManuSrivastava1
Copy link

At the top of our stack is Severus and Draco is at the bottom. Following the FILO principle.
The first pop command will remove from the top - Severus.
The second pop command will remove from the top - rounds
The append command will add to the top - Voldermort

Giving us the final stack as -
deque['Draco','Harry','Hermoine','Voldermort']

@sarabecchi
Copy link

sarabecchi commented Nov 3, 2021

The status of my_stack after the execution of those operations is:

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

esercizio 3

@Postitisnt
Copy link

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

@sanyuezoe
Copy link

from collections import deque
my_stack = deque(["Draco", "Harry", "Hermione", "Ron", "Severus"])
my_stack.pop()
print(my_stack)

deque(['Draco', 'Harry', 'Hermione', 'Ron'])
my_stack.pop()
print(my_stack)

deque(['Draco', 'Harry', 'Hermione'])
my_stack.append("Voldemort")
print(my_stack)

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

@teragramgius
Copy link

my_stack = deque(["Draco", "Harry", "Hermione", "Ron", "Severus"]) 
#a stack is characterized by Last In First Out strategy for adding and removing items. So the process is at it follows.

#I'll go two times with the pop method, to remove the last two items that are "Severus", "Ron"
my_stack.pop()
my_stack.pop()
#then I'll append to the stack the item (a string) "Voldemort"
my_stack.append("Voldemort")

#if I print my_stack, the stack will contain in order "Draco", "Harry", "Hermione", "Voldemort"

print (my_stack)

my_stack = ["Draco", "Harry", "Hermione", "Voldemort"]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests