1"""put and get items from queue"""
2>>> from Queue import Queue
3>>> q = Queue()
4>>> q.put(1)
5>>> q.put(2)
6>>> q.put(3)
7>>> print list(q.queue)
8[1, 2, 3]
9
10>>> q.get()
111
12>>> print list(q.queue)
13[2, 3]
1# Demonstrate queue implementation using list
2
3# Initializing a queue
4queue = []
5
6# Adding elements to the queue
7queue.append('a')
8queue.append('b')
9print(queue)
10
11# Removing elements from the queue
12print("\nElements dequeued from queue")
13print(queue.pop(0))
14print(queue.pop(0))
15
16print("\nQueue after removing elements")
17print(queue)
18
19# print(queue.pop(0)) will raise and IndexError as the queue is now empty
1#creating a queue using list
2
3#defining a list
4
5my_queue =[]
6
7#inserting the items in the queue
8
9my_queue.append(1)
10
11my_queue.append(2)
12
13my_queue.append(3)
14
15my_queue.append(4)
16
17my_queue.append(5)
18
19print("The items in queue:")
20
21print(my_queue)
22
23#removing items from queue
24
25print(my_queue.pop(0))
26
27print(my_queue.pop(0))
28
29print(my_queue.pop(0))
30
31print(my_queue.pop(0))
32
33#printing the queue after removing the elements
34
35print("The items in queue:")
36
37print(my_queue)