from collections import deque
Q = deque()
How to check if this deque is empty? Is there any function like isEmpty() to check this? Can someone help? I looked for a function in the documentation but unable to find any?
from collections import deque
Q = deque()
How to check if this deque is empty? Is there any function like isEmpty() to check this? Can someone help? I looked for a function in the documentation but unable to find any?
Simply pythonic way:
from collections import deque
Q = deque()
if not Q:
print("Queue is empty")
You should know this power of great Python, that each collection becomes false
if it is empty let it be sets, lists, dictionary, deque etc.
if data_structure:
print('Data structure is not empty')
else:
print('Data structure is empty')
The length of Q
will be 0 if the input of deque() is empty:
from collections import deque
Q = deque()
assert len(Q) == 0