Skip to content

Instantly share code, notes, and snippets.

@c3h3
Last active December 23, 2020 10:14
Show Gist options
  • Save c3h3/110edd12b8c904e09d2ffd3c3ccc49b8 to your computer and use it in GitHub Desktop.
Save c3h3/110edd12b8c904e09d2ffd3c3ccc49b8 to your computer and use it in GitHub Desktop.
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