Skip to content

Instantly share code, notes, and snippets.

@bradmwalker bradmwalker/
Last active Aug 29, 2015

What would you like to do?
Modulo-free FizzBuzz
#!/usr/bin/env python3
from itertools import islice, cycle
def str_cycle(str_, n):
return cycle([str_] + (n-1)*[''])
if __name__ == '__main__':
fizzes, buzzes = str_cycle('Fizz', 3), str_cycle('Buzz', 5)
lines = (
''.join(parts) or index
for index, parts in enumerate(zip(fizzes, buzzes))
for line in islice(lines, 1, 101):
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.