RosettaCodeData/Task/FizzBuzz/Python/fizzbuzz-9.py

14 lines
366 B
Python
Raw Permalink Normal View History

2020-02-17 23:21:07 -08:00
from itertools import cycle, izip, count, islice
2019-09-12 10:33:56 -07:00
2020-02-17 23:21:07 -08:00
fizzes = cycle([""] * 2 + ["Fizz"])
buzzes = cycle([""] * 4 + ["Buzz"])
both = (f + b for f, b in izip(fizzes, buzzes))
2019-09-12 10:33:56 -07:00
2020-02-17 23:21:07 -08:00
# if the string is "", yield the number
# otherwise yield the string
fizzbuzz = (word or n for word, n in izip(both, count(1)))
2019-09-12 10:33:56 -07:00
2020-02-17 23:21:07 -08:00
# print the first 100
for i in islice(fizzbuzz, 100):
print i