How to check queue length in Python

前端 未结 4 1506
梦毁少年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:06

    it is simple just use .qsize() example:

    a=Queue()
    a.put("abcdef")
    print a.qsize() #prints 1 which is the size of queue
    

    The above snippet applies for Queue() class of python. Thanks @rayryeng for the update.

    for deque from collections we can use len() as stated here by K Z.

提交回复
热议问题