cpython: 1026b1d47f30 (original) (raw)
Mercurial > cpython
changeset 83037:1026b1d47f30 2.7
Add an itertools recipe showing how to use t.__copy__().
Raymond Hettinger python@rcn.com | |
---|---|
date | Sat, 30 Mar 2013 23:37:57 -0700 |
parents | e044d22d2f61 |
children | cfd4cd15809e |
files | Doc/library/itertools.rst |
diffstat | 1 files changed, 12 insertions(+), 0 deletions(-)[+] [-] Doc/library/itertools.rst 12 |
line wrap: on
line diff
--- a/Doc/library/itertools.rst +++ b/Doc/library/itertools.rst @@ -828,6 +828,18 @@ which incur interpreter overhead. indices = sorted(random.randrange(n) for i in xrange(r)) return tuple(pool[i] for i in indices)
- def tee_lookahead(t, i):
"""Inspect the i-th upcomping value from a tee object[](#l1.8)
while leaving the tee object at its current position.[](#l1.9)
Raise an IndexError if the underlying iterator doesn't[](#l1.11)
have enough values.[](#l1.12)
"""[](#l1.14)
for value in islice(t.__copy__(), i, None):[](#l1.15)
return value[](#l1.16)
raise IndexError(i)[](#l1.17)
+ Note, many of the above recipes can be optimized by replacing global lookups with local variables defined as default values. For example, the dotproduct recipe can be written as::