[Python-checkins] python/nondist/peps pep-0290.txt,1.12,1.13

rhettinger at users.sourceforge.net rhettinger at users.sourceforge.net
Thu Mar 18 02:38:40 EST 2004


Update of /cvsroot/python/python/nondist/peps
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv27010

Modified Files:
	pep-0290.txt 
Log Message:
Note applicability of collections.deque()

Index: pep-0290.txt
===================================================================
RCS file: /cvsroot/python/python/nondist/peps/pep-0290.txt,v
retrieving revision 1.12
retrieving revision 1.13
diff -C2 -d -r1.12 -r1.13
*** pep-0290.txt	10 Jan 2004 10:24:27 -0000	1.12
--- pep-0290.txt	18 Mar 2004 07:38:37 -0000	1.13
***************
*** 102,105 ****
--- 102,127 ----
  -------------------
  
+ Inserting and Popping at the Beginning of Lists
+ '''''''''''''''''''''''''''''''''''''''''''''''
+ 
+ Python's lists are implemented to perform best with appends and pops on
+ the right.  Use of ``pop(0)`` or ``insert(0, x)`` triggers O(n) data
+ movement for the entire list.  To help address this need, Python 2.4
+ introduces a new container, ``collections.deque()`` which has efficient
+ append and pop operations on the both the left and right (the trade-off
+ is much slower getitem/setitem access).  The new container is especially
+ helpful for implementing data queues:
+ 
+ Pattern::
+ 
+     c = list(data)   -->   c = collections.deque(data)
+     c.pop(0)         -->   c.popleft()
+     c.insert(0, x)   -->   c.appendleft()
+ 
+ Locating::
+ 
+     grep pop(0 or
+     grep insert(0
+ 
  Simplifying Custom Sorts
  ''''''''''''''''''''''''




More information about the Python-checkins mailing list