summaryrefslogtreecommitdiffstats
path: root/Doc
diff options
context:
space:
mode:
authorRaymond Hettinger <python@rcn.com>2003-10-26 15:34:50 (GMT)
committerRaymond Hettinger <python@rcn.com>2003-10-26 15:34:50 (GMT)
commitd591f666de4c06cd36624fd513d5bc7d8c031ec8 (patch)
tree69b9a23154c1b1053173bf25421a1cc2c4ce19e0 /Doc
parentf0c5aec85f30ed16d1a8b4d3113bd056881bbf6f (diff)
downloadcpython-d591f666de4c06cd36624fd513d5bc7d8c031ec8.zip
cpython-d591f666de4c06cd36624fd513d5bc7d8c031ec8.tar.gz
cpython-d591f666de4c06cd36624fd513d5bc7d8c031ec8.tar.bz2
Replace the window() example with pairwise() which demonstrates tee().
Diffstat (limited to 'Doc')
-rw-r--r--Doc/lib/libitertools.tex14
1 files changed, 4 insertions, 10 deletions
diff --git a/Doc/lib/libitertools.tex b/Doc/lib/libitertools.tex
index eb6bc49..27e4e45 100644
--- a/Doc/lib/libitertools.tex
+++ b/Doc/lib/libitertools.tex
@@ -405,15 +405,9 @@ def repeatfunc(func, times=None, *args):
else:
return starmap(func, repeat(args, times))
-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
+def pairwise(iterable):
+ "s -> (s0,s1), (s1,s2), (s2, s3), ..."
+ a, b = tee(iterable)
+ return izip(a, islice(b, 1, None))
\end{verbatim}