Skip to content

Instantly share code, notes, and snippets.

@kvalle
Last active June 20, 2016 14:31
Show Gist options
  • Save kvalle/5835007 to your computer and use it in GitHub Desktop.
Save kvalle/5835007 to your computer and use it in GitHub Desktop.
Fizzbuzz, using Python generator expression and iterators
from itertools import cycle, islice, izip, imap
fizz = cycle([""]*2 + ["fizz"])
buzz = cycle([""]*4 + ["buzz"])
fizzbuzz = imap(lambda (i, x): x[0]+x[1] or (i+1), enumerate(izip(fizz,buzz)))
print list(islice(fizzbuzz, 100))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment