Skip to content

Instantly share code, notes, and snippets.

@joelbm24
Created February 19, 2012 23:05
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joelbm24/1866373 to your computer and use it in GitHub Desktop.
Save joelbm24/1866373 to your computer and use it in GitHub Desktop.
fizzbuzz in one line of python
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]))
@andreis
Copy link

andreis commented Oct 19, 2016

print('\n'.join(str(i)*int(i%3>0)*int(i%5>0) + 'Fizz'*int(not i%3) + 'Buzz'*(not i%5) for i in xrange(1,101)))

@ericbaranowski
Copy link

ericbaranowski commented Aug 19, 2018

@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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment