Skip to content

Instantly share code, notes, and snippets.

@cristianrasch
Created March 12, 2019 12:18
Show Gist options
  • Save cristianrasch/5701660ed523b98d9f51c4cb97134ee0 to your computer and use it in GitHub Desktop.
Save cristianrasch/5701660ed523b98d9f51c4cb97134ee0 to your computer and use it in GitHub Desktop.
from itertools import cycle, chain, islice, repeat
fizzes = cycle(chain(islice(repeat(''), 2), ('fizz' for _ in range(1))))
buzzes = cycle(chain(islice(repeat(''), 4), ('buzz' for _ in range(1))))
fizzes_buzzes = zip(range(1, 101), fizzes, buzzes)
fizz_buzz = (str(i) if not(fizz) and not(buzz) else f'{fizz}{buzz}' for i, fizz, buzz in fizzes_buzzes)
for line in fizz_buzz:
print(line)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment