Creating an empty deque in Python with a max length?

后端 未结 1 1416
暖寄归人
暖寄归人 2021-01-12 21:50

I\'m looking at the documentation for a Python deque, and it looks like the constructor is deque([iterable[, maxlen]]). Is there no way to make an empty deque (

相关标签:
1条回答
  • 2021-01-12 22:16

    You could provide a list literal directly, so you don't have to declare anything on a separate line:

    >>> collections.deque([], 42)
    deque([], maxlen=42)
    

    You could also provide maxlen as a named argument:

    >>> collections.deque(maxlen=23)
    deque([], maxlen=23)
    
    0 讨论(0)
提交回复
热议问题