Last active
December 25, 2016 18:23
-
-
Save jaymcgrath/f0d2a5756992ebde1778f27ea2d101a3 to your computer and use it in GitHub Desktop.
Fizzbuzz as a list comprehension
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[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