Welcome, guest | Sign In | My Account | Store | Cart

A Loopless FizzBuzz

Python, 5 lines
1
2
3
4
5
n=map(str, range(101))
n[::3]=['Fizz']*34
n[::5]=['Buzz']*21
n[::15]=['FizzBuzz']*7
print '\n'.join(n[1:])

References :
- -1- - -2- - -3- - -4-

3 comments

Louis RIVIERE (author) 15 years, 3 months ago  # | flag

Alernative :

n=map(str, range(101))
n[::3]=['Fizz']*34
n[::5]=map(lambda a:'FizzBuzz' if a=='Fizz' else 'Buzz', n[::5])
print '\n'.join(n[1:])
Louis RIVIERE (author) 15 years, 3 months ago  # | flag

Alternative :

n=map(str, range(101))
n[::5]=['']*21
n[::3]=['Fizz']*34
n[::5]=map(lambda a:a+'Buzz', n[::5])
print '\n'.join(n[1:])
userend 12 years, 5 months ago  # | flag

That is shorter than the version I came up with.

Created by Louis RIVIERE on Tue, 13 Jan 2009 (MIT)
Python recipes (4591)
Louis RIVIERE's recipes (13)

Required Modules

  • (none specified)

Other Information and Tasks