RosettaCodeData/Task/FizzBuzz/Python/fizzbuzz-8.py
Ingy döt Net 1e05ecd7ee First commit of partial RosettaCode contents.
Pushing this for testing purposes. Lots of work still needed.
2013-04-08 13:02:41 -07:00

13 lines
366 B
Python

from itertools import cycle, izip, count, islice
fizzes = cycle([""] * 2 + ["Fizz"])
buzzes = cycle([""] * 4 + ["Buzz"])
both = (f + b for f, b in izip(fizzes, buzzes))
# if the string is "", yield the number
# otherwise yield the string
fizzbuzz = (word or n for word, n in izip(both, count(1)))
# print the first 100
for i in islice(fizzbuzz, 100):
print i