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

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

@delete4ever
Copy link

delete4ever commented Oct 28, 2022

harry_potter_queue = deque ()
harry_potter_queue.append("Draco")
harry_potter_queue.append("Harry")
harry_potter_queue.append("Hermione")
harry_potter_queue.append("Ron")
harry_potter_queue.append("Severus")
harry_potter_queue.popleft()
# "Draco" was returned and then removed from the left-most part of the queue, now the queue is ["Harry", "Hermione", "Ron", "Severus"]
harry_potter_queue.append("Voldemort")
# "Voldemort" was added to the end of the queue, now the queue is ["Harry", "Hermione", "Ron", "Severus", "Voldemort"]
harry_potter_queue.popleft()
# "Harry" was returned and then removed from the left_most part of the queue, now the queue is ["Hermione", "Ron", "Severus", "Voldemort"]

@mjavadf
Copy link

mjavadf commented Oct 28, 2022

by calling my_queue.popleft() first item of queue will be returned and then will be removed
by calling my_queue.append("Voldemort") the "Voldemort" will be added to end of the queue

  1. queue's status after first my_queue.popleft(): deque(['Harry', 'Hermione', 'Ron', 'Severus'])
  2. queue's status after my_queue.append("Voldemort"): deque(['Harry', 'Hermione', 'Ron', 'Severus', 'Voldemort'])
  3. queue's status after 2nd my_queue.popleft(): deque(['Hermione', 'Ron', 'Severus', 'Voldemort'])

image

@n1kg0r
Copy link

n1kg0r commented Oct 28, 2022

from collections import deque

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

my_queue.popleft() # deque(['Harry', 'Hermione', 'Ron', 'Severus']) <- "Draco" gone from the beginning of the queue
my_queue.append("Voldemort") # deque(['Harry', 'Hermione', 'Ron', 'Severus', 'Voldemort']) <- "Voldemort" appeared at the end of the queue
my_queue.popleft() # deque(['Hermione', 'Ron', 'Severus', 'Voldemort']) <- "Harry" gone from the beginning of the queue

@GaiaOrtona
Copy link

Friends_queue = deque()
Friends_queue.append("Draco")
Friends_queue.append("Harry")
Friends_queue.append("Hermione")
Friends_queue.append("Ron")
Friends_queue.append("Severus")
Friends_queue.popleft()
#based on the FIFO strategy, "Draco" has been removed from the queue
print(Friends_queue)
Friends_queue.append("Voldemort")

"Voldemort" has been added to the queue

print(Friends_queue)
Friends_queue.popleft()
#based on the FIFO strategy, "Harry" has been removed from the queue
print(Friends_queue)

@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.popleft()    # Draco is removed
my_stack.append("Voldemort")      # Voldemort is added at the end of the query
my_stack.popleft()       # Harry is removed
print(my_stack)
print(test_my_stack(my_stack, deque(["Hermione", "Ron", "Severus", "Voldemort"])))

@AmirAliyan74
Copy link

Screenshot (94)

@giorgiacrosilla
Copy link

from collections import deque

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

@lucia1299
Copy link

from collections import deque

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

print(my_queue)

my_queue.popleft()
print(my_queue)

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

my_queue.popleft()
print(my_queue)

OUTPUT(s):

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

@corrado877
Copy link

HarryPotter_Queue

@EricaAndreose
Copy link

03_queue

@mary-lev
Copy link

mary-lev commented Nov 1, 2022

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

@ranacoskun
Copy link

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

@tiglio95
Copy link

tiglio95 commented Nov 2, 2022

HP_queue = deque()
HP_queue.append("Draco")
HP_queue.append("Harry")
HP_queue.append("Hermione")
HP_queue.append("Ron")
HP_queue.append("Severus")
print(HP_queue)
HP_queue.popleft()
HP_queue.append("Voldemort")
HP_queue.popleft()
print(HP_queue)

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

@lvcasmariani
Copy link

Screen Shot 2022-11-02 at 8 41 11 PM

@ChiaraParravicini
Copy link

from collections import deque
my_queue = deque(["Draco", "Harry", "Hermione", "Ron", "Severus"])
my_queue.popleft()
# "Draco", the first item added to the list, has been removed
my_queue.append("Voldemort")
# "Voldemort" has been added after the last item of the list
my_queue.popleft()
# "Harry", now being the first item of the list, has been removed
print(my_queue)
# now my_queue contains: deque(["Hermione", "Ron", "Severus", "Voldemort"])

@alka2696
Copy link

alka2696 commented Nov 8, 2022

Screenshot 2022-11-08 at 2 04 21 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