Created
June 2, 2017 21:39
-
-
Save juanarrivillaga/087e5a2084b1d9c187c9ca3fb7e294a4 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
import string | |
from collections import deque | |
from itertools import islice | |
consumer = deque(maxlen=0) | |
consume = consumer.extend | |
def generator(iterable, steps, consume=consume): | |
it = iter(iterable) | |
yield next(it) | |
for step in steps: | |
consume(islice(it, step)) | |
yield next(it) | |
# >>> list(generator(string.ascii_lowercase, [0, 1, 2, 3])) | |
# ['a', 'b', 'd', 'g', 'k'] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment