How to check queue length in Python

前端 未结 4 1503
梦毁少年i
梦毁少年i 2021-02-03 17:13

How to check Queue\'s length in python?

I dont see they provide Queue.lenght in python....

http://docs.python.org/tutorial/datastructures.html

fr         


        
4条回答
  •  心在旅途
    2021-02-03 18:11

    len(queue) should give you the result, 3 in this case.

    Specifically, len(object) function will call object.__len__ method [reference link]. And the object in this case is deque, which implements __len__ method (you can see it by dir(deque)).


    queue= deque([])   #is this length 0 queue?
    

    Yes it will be 0 for empty deque.

提交回复
热议问题