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 #14

Open
essepuntato opened this issue Oct 28, 2022 · 16 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").

@delete4ever
Copy link

delete4ever commented Oct 28, 2022

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"]

@mjavadf
Copy link

mjavadf commented Oct 28, 2022

by calling my_stack.pop() the top item of stack will be returned and then will be removed
stack status after calling this method 2 times: deque(['Draco', 'Harry', 'Hermione'])
by calling harry_potter_stack.append("Voldemort") the '"Voldemort" will be added to top of the stack
stack status after calling this method: deque(['Draco', 'Harry', 'Hermione', 'Voldemort'])
image

@n1kg0r
Copy link

n1kg0r commented Oct 28, 2022

from collections import deque

my_stack = deque(["Draco", "Harry", "Hermione", "Ron", "Severus"])
my_stack.pop() # deque(['Draco', 'Harry', 'Hermione', 'Ron']) <- "Severus" taken from the 'top' of the stack
my_stack.pop() # deque(['Draco', 'Harry', 'Hermione']) <- "Ron" taken from the 'top' of the stack
my_stack.append("Voldemort") # deque(['Draco', 'Harry', 'Hermione']) <- "Voldemort" put on the 'top' of the stack

@GaiaOrtona
Copy link

from collections import deque

Friends_stack = deque()
Friends_stack.append("Draco")
Friends_stack.append("Harry")
Friends_stack.append("Hermione")
Friends_stack.append("Ron")
Friends_stack.append("Severus")
Friends_stack.pop()
#based on the LIFO strategy, "Severus" has been removed from the stack
print(Friends_stack)
Friends_stack.pop()
#based on the LIFO strategy, "Ron" has been removed from the stack
print(Friends_stack)
Friends_stack.append("Voldemort")
#"Voldemort" has been added to the stack
print(Friends_stack)

@SalvatoreDiMarzo
Copy link

from _collections import deque

def test_my_stack(my_list, expected):
    if my_list == expected:
        return True
    else:
        return False

my_stack = deque(["Draco", "Harry", "Hermione", "Ron", "Severus"])
my_stack.pop()      # Severus is removed#
my_stack.pop()      # Ron is removed#
my_stack.append("Voldemort")       # Voldemort is added#
print(my_stack)
print(test_my_stack(my_stack, deque(["Draco", "Harry", "Hermione", "Voldemort"])))

@AmirAliyan74
Copy link

Screenshot (93)

@giorgiacrosilla
Copy link

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)

@lucia1299
Copy link

from collections import deque

my_stack = deque ()
my_stack.append("Harry")
my_stack.append("Hermione")
my_stack.append("Ron")
my_stack.append("Draco")
my_stack.append("Severus")

print(my_stack)

my_stack.pop()
print(my_stack)

my_stack.pop()
print(my_stack)

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

OUTPUT(s):

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

@corrado877
Copy link

HarryPotter_Stack

@EricaAndreose
Copy link

02_stack

@mary-lev
Copy link

mary-lev commented Nov 1, 2022

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

@ranacoskun
Copy link

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

@tiglio95
Copy link

tiglio95 commented Nov 2, 2022

my_stack = deque()
my_stack.append("Draco")
my_stack.append("Harry")
my_stack.append("Hermione")
my_stack.append("Ron")
my_stack.append("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', 'Voldemort'])

@lvcasmariani
Copy link

Screen Shot 2022-11-02 at 8 29 51 PM

@ChiaraParravicini
Copy link

from collections import deque

my_stack = deque(["Draco", "Harry",
"Hermione", "Ron", "Severus"])
my_stack.pop()
# "Severus", the item on top of the stack, has been removed 
my_stack.pop()
# "Ron", now being the item on top of the stack, has been removed
my_stack.append("Voldemort")
# "Voldermort" has been added on top of the stack
print(my_stack)
# now my_stack contains: deque(["Draco", "Harry", "Hermione", "Voldemort"])

@alka2696
Copy link

alka2696 commented Nov 8, 2022

Screenshot 2022-11-08 at 1 58 17 PM

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