5 ms·
Two more variants. The first is precomputed without code-based initialization: fizzbuzz = ['FizzBuzz', None, None, 'Fizz', None, 'Buzz', 'Fizz', None,
by dmayle 13y ago
Two more variants. The first is precomputed without code-based initialization:
fizzbuzz = ['FizzBuzz', None, None, 'Fizz', None, 'Buzz', 'Fizz', None,
None, 'Fizz', 'Buzz', None, 'Fizz', None, None]
for x in xrange(1, 101):
print fizzbuzz[x % 15] or x
The second is unique in that there are no conditionals at all. (Not efficient, especially for large numbers)
fizzbuzz = ['FizzBuzz', 1, 1, 'Fizz ', 1, 'Buzz ', 'Fizz ',
1, 1, 'Fizz ', 'Buzz ', 1, 'Fizz ', 1, 1]
for x in xrange(1, 101):
print str(fizzbuzz[x % 15] * x)[:8]