Skip to content

Instantly share code, notes, and snippets.

@muzhig
Created January 16, 2018 13:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save muzhig/dac900485fe8b8b9c2a3605cb02d46d3 to your computer and use it in GitHub Desktop.
Save muzhig/dac900485fe8b8b9c2a3605cb02d46d3 to your computer and use it in GitHub Desktop.
Fizzbuzz
import itertools
def fizzbuzz():
for i in itertools.count(1):
fizz = i % 3 == 0
buzz = i % 5 == 0
if fizz and buzz:
yield 'fizz buzz'
elif fizz:
yield 'fizz'
elif buzz:
yield 'buzz'
else:
yield i
if __name__ == '__main__':
print(
list(
itertools.islice(fizzbuzz(), 20)
)
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment