Last active
December 23, 2020 10:14
-
-
Save c3h3/110edd12b8c904e09d2ffd3c3ccc49b8 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
from itertools import islice, imap, tee | |
from operator import add | |
def tail(iterable): | |
return islice(iterable, 1, None) | |
def take(n, iterable): | |
return list(islice(iterable, 0, n)) | |
def fibs(): | |
yield 1 | |
yield 1 | |
fibs1, fibs2 = tee(fibs()) | |
yield from map(add, fibs1, tail(fibs2)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment