Issue
I have
from collections import deque
dq = deque(range(10), maxlen = 10)
dq
dq.extendleft([10, 20, 30, 40])
dq
result
deque([40, 30, 20, 10, 3, 4, 5, 6, 7, 8])
but in book Fluent Python (2019), I see maxlen, like this
deque([40, 30, 20, 10, 3, 4, 5, 6, 7, 8], maxlen=10)
Is the different cause by version different?
Solution
This seems to be caused by IPython. If you do print(dq)
or print(repr(dq))
, you get your expected output, and same in a normal REPL.
In [1]: from collections import deque
In [2]: dq = deque(range(10), maxlen=10)
In [3]: dq
Out[3]: deque([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])
In [4]: print(dq)
deque([0, 1, 2, 3, 4, 5, 6, 7, 8, 9], maxlen=10)
In [5]: print(repr(dq))
deque([0, 1, 2, 3, 4, 5, 6, 7, 8, 9], maxlen=10)
>>> from collections import deque
>>> dq = deque(range(10), maxlen=10)
>>> dq
deque([0, 1, 2, 3, 4, 5, 6, 7, 8, 9], maxlen=10)
Update: I've submitted a PR to IPython to fix the problem.
Answered By - wjandrea
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.