[Python-checkins] python/dist/src/Doc/lib libitertools.tex, 1.21, 1.22

rhettinger at users.sourceforge.net rhettinger at users.sourceforge.net
Wed Nov 12 09:32:28 EST 2003


Update of /cvsroot/python/python/dist/src/Doc/lib
In directory sc8-pr-cvs1:/tmp/cvs-serv16547/Doc/lib

Modified Files:
	libitertools.tex 
Log Message:
Improve the implementation of itertools.tee().

Formerly, underlying queue was implemented in terms of two lists.  The
new queue is a series of singly-linked fixed length lists.

The new implementation runs much faster, supports multi-way tees, and
allows tees of tees without additional memory costs.

The root ideas for this structure were contributed by Andrew Koenig
and Guido van Rossum.



Index: libitertools.tex
===================================================================
RCS file: /cvsroot/python/python/dist/src/Doc/lib/libitertools.tex,v
retrieving revision 1.21
retrieving revision 1.22
diff -C2 -d -r1.21 -r1.22
*** libitertools.tex	26 Oct 2003 15:34:50 -0000	1.21
--- libitertools.tex	12 Nov 2003 14:32:25 -0000	1.22
***************
*** 282,288 ****
  \end{funcdesc}
  
! \begin{funcdesc}{tee}{iterable}
!   Return two independent iterators from a single iterable.
!   Equivalent to:
  
    \begin{verbatim}
--- 282,288 ----
  \end{funcdesc}
  
! \begin{funcdesc}{tee}{iterable\optional{, n=2}}
!   Return \var{n} independent iterators from a single iterable.
!   The case where \var{n} is two is equivalent to:
  
    \begin{verbatim}
***************
*** 300,303 ****
--- 300,307 ----
    \end{verbatim}
  
+   Note, once \function{tee()} has made a split, the original \var{iterable}
+   should not be used anywhere else; otherwise, the \var{iterable} could get
+   advanced without the tee objects being informed.
+ 
    Note, this member of the toolkit may require significant auxiliary
    storage (depending on how much temporary data needs to be stored).
***************
*** 409,413 ****
      "s -> (s0,s1), (s1,s2), (s2, s3), ..."
      a, b = tee(iterable)
!     return izip(a, islice(b, 1, None))
  
  \end{verbatim}
--- 413,421 ----
      "s -> (s0,s1), (s1,s2), (s2, s3), ..."
      a, b = tee(iterable)
!     try:
!         b.next()
!     except StopIteration:
!         pass
!     return izip(a, b)
  
  \end{verbatim}





More information about the Python-checkins mailing list