[Python-checkins] r79483 - python/trunk/Doc/library/itertools.rst
raymond.hettinger
python-checkins at python.org
Sun Mar 28 20:25:01 CEST 2010
Author: raymond.hettinger
Date: Sun Mar 28 20:25:01 2010
New Revision: 79483
Log:
Update itertools recipe for consume().
Modified:
python/trunk/Doc/library/itertools.rst
Modified: python/trunk/Doc/library/itertools.rst
==============================================================================
--- python/trunk/Doc/library/itertools.rst (original)
+++ python/trunk/Doc/library/itertools.rst Sun Mar 28 20:25:01 2010
@@ -672,7 +672,13 @@
def consume(iterator, n):
"Advance the iterator n-steps ahead. If n is none, consume entirely."
- collections.deque(islice(iterator, n), maxlen=0)
+ # Use functions that consume iterators at C speed.
+ if n is None:
+ # feed the entire iterator into a zero-length deque
+ collections.deque(iterator, maxlen=0)
+ else:
+ # advance to the emtpy slice starting at position n
+ next(islice(iterator, n, n), None)
def nth(iterable, n, default=None):
"Returns the nth item or a default value"
More information about the Python-checkins
mailing list