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?
Asked
Active
Viewed 2.0k times
13

itsmichaelwang
- 2,282
- 4
- 16
- 25
-
1The iterable can be an empty list or tuple. – mdurant Sep 30 '14 at 15:42
1 Answers
26
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)

Kevin
- 74,910
- 12
- 133
- 166