Friday, May 8, 2009

Python FizzBuzz oneliner

From a comment on this blog via this blog

for i in range(1,101):print"FizzBuzz"[i*i%3*4:8--i**4%5]or i

This is mine (May, 17, 18 modified)

print '\n'.join(['Fizz'*(not i%3) + 'Buzz'*(not i%5) or str(i) for i in range(1, 101)])

I post this topic on a Python forum and a guy posted this, nice.

for x in range(100): print x%3/2*'Fizz'+x%5/4*'Buzz' or x+1


Anonymous said...

Here's my entry!

for i in range(1,101):print "".join((i%x[0]==0)*x[1] for x in [(3,"fizz"),(5,"buzz")]) or i

(taken from my blog)

hohehohe2 [at] said...

That's a good one!

and I found mine has a redundancy inside join ;)

Chris said...

wow, that last one is REALLY short! here is mine
for i in range(1,101):print"Fizz"*(i%3<1)+"Buzz"*(i%5<1)or i

hohehohe2 [at] said...


oh that's simple and short, i like the style :)