Answers for "python queue using list example"

2

python get item from queue

"""put and get items from queue"""
>>> from Queue import Queue
>>> q = Queue()
>>> q.put(1)
>>> q.put(2)
>>> q.put(3)
>>> print list(q.queue)
[1, 2, 3]

>>> q.get()
1
>>> print list(q.queue)
[2, 3]
Posted by: Guest on April-04-2020
0

queue in python

#creating a queue using list

#defining a list

my_queue =[]

#inserting the items in the queue

my_queue.append(1)

my_queue.append(2)

my_queue.append(3)

my_queue.append(4)

my_queue.append(5)

print("The items in queue:")

print(my_queue)

#removing items from queue

print(my_queue.pop(0))

print(my_queue.pop(0))

print(my_queue.pop(0))

print(my_queue.pop(0))

#printing the queue after removing the elements

print("The items in queue:")

print(my_queue)
Posted by: Guest on March-21-2021

Python Answers by Framework

Browse Popular Code Answers by Language