Created
February 19, 2012 23:05
-
-
Save joelbm24/1866373 to your computer and use it in GitHub Desktop.
fizzbuzz in one line of python
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
for i in range(1,101): print (lambda x: x[2]==True and "fizzbuzz" or x[1]==True and "buzz" or x[0]==True and "fizz" or i)(map(lambda x: x(i), [lambda x: x%3==0, lambda x: x%5==0, lambda x: x%5==0 and x%3==0])) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@konstantinfarrell has a gist that’s only 72 characters for anyone arriving to this page from google:
for i in range(1, 101): print('Fizz'*(i%3==0)+'Buzz'*(i%5==0) or str(i))
@andreis line should work with both python 2 and 3 by changing xrange() to range()
Here’s a nice little piece on the range() function.