r/Python • • Jan 23 '17

Share your unusual fizzbuzz approaches!

Dear /r/Python, I would like you to share your FizzBuzz. Here is mine:

import numpy as np

fb = np.arange(101, dtype='object')
fb[::3] = 'Fizz'
fb[::5] = 'Buzz'
fb[::15] = 'FizzBuzz'

print(*fb[1:], sep='\n')
4 Upvotes

20 comments sorted by

View all comments

Show parent comment

5

u/vipul20 Jan 23 '17

or a cleaner list comprehension:

[(x%3==0)*'Fizz' + (x%5==0)*'Buzz' or x for x in range(1, 101)]

2

u/The_Jeremy Jan 23 '17

with Gprime5's changes, yours is the shortest so far:

[(1-x%3)*'Fizz' + (1-x%5)*'Buzz' or x for x in range(1, 101)]