[Python-checkins] python/dist/src/Doc/lib libitertools.tex,1.9,1.10
rhettinger@users.sourceforge.net
rhettinger@users.sourceforge.net
Wed, 18 Jun 2003 12:25:39 -0700
Update of /cvsroot/python/python/dist/src/Doc/lib
In directory sc8-pr-cvs1:/tmp/cvs-serv15836/Doc/lib
Modified Files:
libitertools.tex
Log Message:
Minor updates:
* Updated comment on design of imap()
* Added untraversed object in izip() structure
* Replaced the pairwise() example with a more general window() example
Index: libitertools.tex
===================================================================
RCS file: /cvsroot/python/python/dist/src/Doc/lib/libitertools.tex,v
retrieving revision 1.9
retrieving revision 1.10
diff -C2 -d -r1.9 -r1.10
*** libitertools.tex 2 May 2003 19:44:20 -0000 1.9
--- libitertools.tex 18 Jun 2003 19:25:37 -0000 1.10
***************
*** 359,366 ****
... return not nth(ifilter(pred, seq), 0)
- >>> def pairwise(seq):
- ... "s -> (s0,s1), (s1,s2), (s2, s3), ..."
- ... return izip(seq, islice(seq,1,None))
-
>>> def padnone(seq):
... "Returns the sequence elements and then returns None indefinitely"
--- 359,362 ----
***************
*** 373,376 ****
--- 369,383 ----
>>> def dotproduct(vec1, vec2):
... return sum(imap(operator.mul, vec1, vec2))
+
+ >>> def window(seq, n=2):
+ ... "Returns a sliding window (of width n) over data from the iterable"
+ ... " s -> (s0,s1,...s[n-1]), (s1,s2,...,sn), ... "
+ ... it = iter(seq)
+ ... result = tuple(islice(it, n))
+ ... if len(result) == n:
+ ... yield result
+ ... for elem in it:
+ ... result = result[1:] + (elem,)
+ ... yield result
\end{verbatim}