DEV Community

Arunkumar Dharuman
Arunkumar Dharuman

Posted on

2 1

fixed length queue

To create a fixed length queue and to discard old values as you and new values

from collections import deque

dq = deque(maxlen=5)

for i in range(10):
    dq.append(i)

print(dq)
Enter fullscreen mode Exit fullscreen mode

Output:
deque([5, 6, 7, 8, 9], maxlen=5)

Top comments (0)

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay