Last active
June 20, 2016 14:31
-
-
Save kvalle/5835007 to your computer and use it in GitHub Desktop.
Fizzbuzz, using Python generator expression and iterators
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
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