Skip to content

Instantly share code, notes, and snippets.

@jaymcgrath
Last active December 25, 2016 18:23
Show Gist options
  • Save jaymcgrath/f0d2a5756992ebde1778f27ea2d101a3 to your computer and use it in GitHub Desktop.
Save jaymcgrath/f0d2a5756992ebde1778f27ea2d101a3 to your computer and use it in GitHub Desktop.
Fizzbuzz as a list comprehension
[str(x) * int(bool(x % 3 and x % 5)) + "Fizz" * int(not bool(x % 3)) + "Buzz" * int(not bool(x % 5)) for x in range(1,101)]
# works, but could probably be condensed
# Condensed version, non list comp
for i in range(1,101):print('Fizz'*(0==i%3)+'Buzz'*(0==i%5)or i)
refactored as a list comp:
['Fizz'*(0==i%3)+'Buzz'*(0==i%5)or i for i in range(1,101)]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment