Skip to content

Instantly share code, notes, and snippets.

@slykar
Created March 30, 2020 18:21
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 slykar/565b158e53753c340a13245a6034f396 to your computer and use it in GitHub Desktop.
Save slykar/565b158e53753c340a13245a6034f396 to your computer and use it in GitHub Desktop.
Declarative FizzBuzz in Python
FROM = 1
TO = 100
DIVIDERS = [
(3, "Fizz"),
(5, "Buzz"),
(7, "Kazz") # or any other (div, word) pair
]
for n in range(FROM, TO):
output_words = [word for div, word in DIVIDERS if n % div == 0]
print(''.join(output_words) if output_words else n)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment