rfmonk

collections_deque_consuming.py

Jan 9th, 2014
181
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.33 KB | None | 0 0
  1. #!/usr/bin/env python
  2.  
  3.  
  4. import collections
  5.  
  6. print 'From the right:'
  7. d = collections.deque('abcdefg')
  8. while True:
  9.     try:
  10.         print d.pop(),
  11.     except IndexError:
  12.         break
  13. print
  14.  
  15. print '\nFrom the left:'
  16. d = collections.deque(xrange(6))
  17. while True:
  18.     try:
  19.         print d.popleft(),
  20.     except IndexError:
  21.         break
  22. print
Advertisement
Add Comment
Please, Sign In to add comment