Skip to content

Instantly share code, notes, and snippets.

@ashwin
Created March 23, 2013 15:21
Show Gist options
  • Save ashwin/5228081 to your computer and use it in GitHub Desktop.
Save ashwin/5228081 to your computer and use it in GitHub Desktop.
How to implement a queue with maximum length in Python
# Queue with max length of 3
from collections import deque
q = deque( maxlen=3 )
# deque([])
q.append( 10 )
q.append( 20 )
q.append( 30 )
# deque([ 10, 20, 30 ])
q.append( 40 )
# deque([ 20, 30, 40 ])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment