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 3 #16

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

Comments

@essepuntato
Copy link
Contributor

Consider to have a queue obtained by processing, one by one, the elements included in the list of the first exercise, i.e. my_queue = deque(["Draco", "Harry", "Hermione", "Ron", "Severus"]). Describe the status of my_queue after the execution of each of the following operations: my_queue.popleft(), my_queue.append("Voldemort"), my_queue.popleft().

@giorgimariachiara
Copy link

The status of my_queue after all the operations is: Harry, Hermione, Ron, Severus

@elizastuglik
Copy link

After the execution of the operations the status of my_queue Will be: Harry, Hermione, Ron, Severus

@sotarega
Copy link

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

my_queue.popleft()                  #removes first element from left (in this case 'Draco' and releases it)
print(my_queue)
['Harry', 'Hermione', 'Ron', 'Severus']

my_queue.append("Voldemort")
print(my_queue)
['Harry', 'Hermione', 'Ron', 'Severus', 'Voldemort']

my_queue.popleft()
print(my_queue)
['Hermione', 'Ron', 'Severus', 'Voldemort']

@tommasobattisti
Copy link

my_queue will contain the following items:
"Hermione", "Ron", "Severus", "Voldemort".

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

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

@ManueleVeggi
Copy link

ManueleVeggi commented Oct 25, 2021

Even though not performed in a row, the two commands my_queue.popleft() will remove the first elements, which are 'Draco' and 'Harry'. The command my_queue.append will add the 'Voldemort' at the end of the stack. The result is hence:
['Hermione', 'Ron', 'Severus', 'Voldemort']

@ghasempouri1984
Copy link

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

from collections import deque

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

my_queue.popleft()
print(my_queue)

my_queue.append("Voldemort")
print(my_queue)

my_queue.popleft()
print(my_queue)

@CarmenSantaniello
Copy link

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

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

Popleft() method removes "Draco" as it is the first item on the left of the queue, then append() method adds "Voldemort" as a new item and puts it at the rightmost side of the queue, lastly popleft() method once again removes the new first item "Harry".

@angstigone
Copy link

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

my_queue.popleft()

queue becomes (["Harry", "Hermione", "Ron", "Severus"])

my_queue.append("Voldemort")

queue becomes (["Harry", "Hermione", "Ron", "Severus", "Voldemort"])

my_queue.popleft()

queue becomes (["Hermione", "Ron", "Severus", "Voldemort"])

@francescabudel
Copy link

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

print(my_queue)
deque(['Hermione', 'Ron', 'Severus', 'Voldemort'])

@NoraPs
Copy link

NoraPs commented Oct 26, 2021

from collections import deque

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

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

@MaddaGh
Copy link

MaddaGh commented Oct 26, 2021

queue

deque(["Hermione", "Ron", "Severus", "Voldemort"])

@OrsolaMBorrini
Copy link

OrsolaMBorrini commented Oct 26, 2021

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

@sterenz
Copy link

sterenz commented Oct 27, 2021

from collections import deque

my_queue = deque(["Draco", "Harry", "Hermione", "Ron", "Severus"])
my_queue.popleft() # the first to arrive now leaves
print(my_queue)
# deque(['Harry', 'Hermione', 'Ron', 'Severus'])

my_queue.append("Voldemort") # Voldemort arrives
print(my_queue)
# deque(['Harry', 'Hermione', 'Ron', 'Severus', 'Voldemort'])

my_queue.popleft() # the second to arrive now leaves
print(my_queue)
# deque(['Hermione', 'Ron', 'Severus', 'Voldemort'])

@RebeccaJillianBeattie
Copy link

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

my_queue.popleft()
["Harry", "Hermione", "Ron", "Severus"]

my_queue.append("Voldemort")
["Harry", "Hermione", "Ron", "Severus", "Voldemort"]

my_queue.popleft()
["Hermione", "Ron", "Severus", "Voldemort"]

@olgagolgan
Copy link

image
image

@SaraVell1
Copy link

image

@AnastasiyaSopyryaeva
Copy link

INPUT
from typing import Deque

my_queue = Deque(["Draco", "Harry", "Hermione", "Ron", "Severus"])
print(my_queue)

my_queue.popleft()
print(my_queue)

my_queue.append("Voldemort")
print(my_queue)

my_queue.popleft()
print(my_queue)

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

@martasoricetti
Copy link

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

my_queue.popleft ( ) # it removes the first item added
print(my_queue)
deque (["Harry", "Hermione", "Ron", "Severus"])

my_queue.append ( "Voldemort")
print(my_queue)
deque (["Harry", "Hermione", "Ron", "Severus", "Voldemort"])

my_queue.popleft ( )
print (my_queue)
deque (["Hermione", "Ron", "Severus", "Voldemort"])

@PirjoElbrecht
Copy link

from collections import deque # import statement
my_queue = deque(["Draco", "Harry", "Hermione", "Ron", "Severus"])

my_queue.popleft()
print(my_queue)
#result deque(['Harry', 'Hermione', 'Ron', 'Severus'])

my_queue.append("Voldemort")
print(my_queue)
#result deque(['Harry', 'Hermione', 'Ron', 'Severus', 'Voldemort'])

my_queue.popleft()
print(my_queue)
#result deque(['Hermione', 'Ron', 'Severus', 'Voldemort'])

@chloeppd
Copy link

Screenshot 2021-10-28 at 4 44 52 PM

@AmeliaLamargese
Copy link

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

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

after my_queue.append("Voldemort") function, "Voldemort" will be added to the queue as the last item
my_queue = ["Harry", "Hermione", "Ron", "Severus", "Voldemort"]

with the execution of my_queue.popleft() function, the first item will be removed,
in this case "Harry" will be deleted and returned
my_queue = ["Hermione", "Ron", "Severus", "Voldemort"]

@ManuSrivastava1
Copy link

pop.left will remove "Drace" from the stack(which is being treated like a queue at this point)
Appeand will add "Voldermort" at top/right to the stack
pop.left will remove "Harry" from the stack. leaving us the following :

deque['Hermoine','Ron','Severus','Voldermort']

@sarabecchi
Copy link

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

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

esercizio 4

@Postitisnt
Copy link

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

@sanyuezoe
Copy link

sanyuezoe commented Nov 6, 2021

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

deque(['Harry', 'Hermione', 'Ron', 'Severus'])
my_queue.append("Voldemort")
print(my_queue)

deque(['Harry', 'Hermione', 'Ron', 'Severus', 'Voldemort'])
my_queue.popleft()
print(my_queue)

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

@teragramgius
Copy link

teragramgius commented Nov 22, 2021

The status of my_queue after the execution of each operation will be my_queue = (["Hermione", "Ron", "Severus", "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