
Introduction
Queues are one of the crucial linear types of data structures that have ample applications in various areas of computer science and the many real-world scenarios and examples that it is seen in, such as booking tickets in ticket lines/queues, placing requests to pre-buy products online, etc. In Python, Queues can either be implemented or directly be used through different available libraries such as collections and queues.
In this article, we will see various techniques to dump/convert the items stored in a queue in the form of a list or Array in Python.
Also see, Arrays

Approach 1
Dequeuing Elements and Appending them back in a list/array
One can use the deque method offered in queues to dump all the items present in a list or an array. This can be done by dequeuing all elements from a queue and appending them into a list or an array.
One can do this in the following manner:
Code:
# Approach 1 for Dumping queue into a list
from collections import deque
from queue import Queue
# Initializing a queue
q = deque()
# Adding elements to a queue
q.append('a')
q.append('b')
q.append('c')
# display the queue
print("Queue using collections.deque: ")
print(q)
# display the type
print(type(q),"\n")
# converting into list
li1 = []
while len(q) > 0:
li1.append(q.popleft())
# display
print("First Converted list: ")
print(li1)
print(type(li1), '\n')
que = Queue()
que.put(10)
que.put(9)
que.put(6)
que.put(8)
# display the queue
print("Queue using queue.Queue: ")
print(que.queue)
# display the type
print(type(que),"\n")
# converting into list
li2 = []
while que.qsize() > 0:
li2.append(que.get())
# display
print("First Converted list: ")
print(li2)
print(type(li2), '\n')
Output:
Queue using collections.deque:
deque(['a', 'b', 'c'])
<class 'collections.deque'>
First Converted list:
['a', 'b', 'c']
<class 'list'>
Queue using queue.Queue:
deque([10, 9, 6, 8])
<class 'queue.Queue'>
First Converted list:
[10, 9, 6, 8]
<class 'list'>
You can also practice with the help of Online Python Compiler
Explanation
As you can see here, we were able to dump the elements in the queue in a list/array using the deque methods that the various library implementations of queues in Python.
First, we saw how dumping elements from collections.deque implementation of queues in Python can be done using the ‘popleft()’ method present in the library.
While for queue.Queue implementation of queues in python one can use ‘get()’ to deque the elements from the queue to a list/array quickly.
Time Complexity: O(n), traversing the queue to traverse the items and append them in a list/array.
Space Complexity: O(1) as no extra space was required in the intermediate dequeuing steps.
Also see, Collections