Search notes:

Python standard library: collections.deque

A deque object is similar to a list object. The main difference is that operations at a deque's end are faster but operations in between are slower.
from collections import deque

D = deque([ 'one', 'two', 'three', 'four' ])

#
#   Add items on the deque's right side:
#
D.append('five')

#
#   Add another item (which happens to be a list):
#
D.append([ 'six', 'seven' ])

#
# Add an on the deque's left side:
#
D.appendleft('zero')

print(D)
#
#  deque(['zero', 'one', 'two', 'three', 'four', 'five', ['six', 'seven']])


#
# Remove items on the right side
#
print(D.pop())     # ['six', 'seven']
print(D.pop())     #  five

#
# Remove an item on the left side
#
print(D.popleft()) # zero

print(D)           #  deque(['one', 'two', 'three', 'four'])
Github repository about-Python, path: /standard-library/collections/deque/demo.py

See also

list

Index

Fatal error: Uncaught PDOException: SQLSTATE[HY000]: General error: 8 attempt to write a readonly database in /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php:78 Stack trace: #0 /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php(78): PDOStatement->execute(Array) #1 /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php(30): insert_webrequest_('/notes/developm...', 1758206546, '216.73.216.150', 'Mozilla/5.0 App...', NULL) #2 /home/httpd/vhosts/renenyffenegger.ch/httpsdocs/notes/development/languages/Python/standard-library/collections/deque/index(76): insert_webrequest() #3 {main} thrown in /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php on line 78