Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Creating an empty deque in Python with a max length?

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 (that is, without specifying the iterable) with a max length?

like image 390
itsmichaelwang Avatar asked Sep 30 '14 15:09

itsmichaelwang


1 Answers

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)
like image 95
Kevin Avatar answered Oct 06 '22 07:10

Kevin