是否有不同的方法来检查python中的deque空(is there a different ways to check deque empty in python)
它们是一样的吗????
while len(deque)>0: deque.popleft() while deque: deque.popleft()所以基本上这两个条件循环可以避免从空队列中弹出?
Are they the same thing????
while len(deque)>0: deque.popleft() while deque: deque.popleft()so basically these two condition loops can avoid poping from empty queue?
最满意答案
它们是相同的,但PEP 8更喜欢第二个版本。 我不相信它总是更容易阅读,所以要用自己的判断。
http://www.python.org/dev/peps/pep-0008/#programming-recommendations
对于序列,(字符串,列表,元组),请使用空序列为假的事实。
Yes: if not seq: if seq: No: if len(seq) if not len(seq)
They're the same, but PEP 8 prefers the second version. I'm not convinced that it's always easier to read though, so use your own judgement.
http://www.python.org/dev/peps/pep-0008/#programming-recommendations
For sequences, (strings, lists, tuples), use the fact that empty sequences are false.
Yes: if not seq: if seq: No: if len(seq) if not len(seq)
更多推荐
发布评论