diff options
author | Raymond Hettinger <python@rcn.com> | 2003-06-18 19:25:37 (GMT) |
---|---|---|
committer | Raymond Hettinger <python@rcn.com> | 2003-06-18 19:25:37 (GMT) |
commit | befa37dd05050ecce9637d81ebe9d8d74688129c (patch) | |
tree | 904725503d82dda010c10fecb8bb6327d98c9c4d /Doc | |
parent | 3a8fbe7eeca4cc8cb944c8120690e54a6c775747 (diff) | |
download | cpython-befa37dd05050ecce9637d81ebe9d8d74688129c.zip cpython-befa37dd05050ecce9637d81ebe9d8d74688129c.tar.gz cpython-befa37dd05050ecce9637d81ebe9d8d74688129c.tar.bz2 |
Minor updates:
* Updated comment on design of imap()
* Added untraversed object in izip() structure
* Replaced the pairwise() example with a more general window() example
Diffstat (limited to 'Doc')
-rw-r--r-- | Doc/lib/libitertools.tex | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/Doc/lib/libitertools.tex b/Doc/lib/libitertools.tex index f291fe3..e146c6c 100644 --- a/Doc/lib/libitertools.tex +++ b/Doc/lib/libitertools.tex @@ -358,10 +358,6 @@ from building blocks. ... "Returns True if pred(x) is False for every element in the iterable" ... 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" ... return chain(seq, repeat(None)) @@ -373,4 +369,15 @@ from building blocks. >>> 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} |