如何检查 Python 中的双端队列是否为空?
How to check if this deque is empty in Python?
from collections import deque
Q = deque()
如何检查这个双端队列是否为空?有没有像 isEmpty() 这样的函数来检查这个?有人可以帮忙吗?我在文档中查找函数但找不到?
如果 deque() 的输入为空,Q
的长度将为 0:
from collections import deque
Q = deque()
assert len(Q) == 0
简单的pythonic方式:
from collections import deque
Q = deque()
if not Q:
print("Queue is empty")
你应该知道这种伟大的力量 Python,每个集合都变成 false
如果它是空的让它成为集合、列表、字典、双端队列等
if data_structure:
print('Data structure is not empty')
else:
print('Data structure is empty')
from collections import deque
Q = deque()
如何检查这个双端队列是否为空?有没有像 isEmpty() 这样的函数来检查这个?有人可以帮忙吗?我在文档中查找函数但找不到?
如果 deque() 的输入为空,Q
的长度将为 0:
from collections import deque
Q = deque()
assert len(Q) == 0
简单的pythonic方式:
from collections import deque
Q = deque()
if not Q:
print("Queue is empty")
你应该知道这种伟大的力量 Python,每个集合都变成 false
如果它是空的让它成为集合、列表、字典、双端队列等
if data_structure:
print('Data structure is not empty')
else:
print('Data structure is empty')