Created
February 24, 2012 11:06
-
-
Save fumieval/1900177 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def consume(iterator, n=None): | |
"Advance the iterator n-steps ahead. If n is none, consume entirely." | |
# 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 empty slice starting at position n | |
next(islice(iterator, n, n), None) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment