Skip to content

Instantly share code, notes, and snippets.

@Torvaney
Last active October 26, 2020 14:18
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 Torvaney/baccb2209257f94c0ffac56163a2052a to your computer and use it in GitHub Desktop.
Save Torvaney/baccb2209257f94c0ffac56163a2052a to your computer and use it in GitHub Desktop.
FIZZBUZZ_SPEC = {
3: 'fizz',
5: 'buzz'
}
def fizzbuzz_item(x, spec=FIZZBUZZ_SPEC):
return ''.join(v for k, v in spec.items() if (x % k) == 0) or str(x)
def fizzbuzz(xs, spec=FIZZBUZZ_SPEC):
yield from (fizzbuzz_item(x, spec=spec) for x in xs)
if __name__ == '__main__':
for x in fizzbuzz(range(1, 101)):
print(x)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment