The Theo Spears Blog

Blogging Considered Harmful (Considered Harmful)?

FizzBuzz in Python

First posted 2007-08-13 00:00:00+00:00

Yesterday I blogged about implementing an enterprise version of FizzBuzz in C#. Here's one possibly python version to compare.



#!/usr/bin/python



x = [""] * 100
for i in range(2,100,3): x[i] = "Fizz"
for i in range(4,100,5): x[i] += "Buzz"
print "".join(x[i] if x[i] else str(i+1) for i in range(0,100))


Before anyone comments, I know it is possible to make the C# version shorter, and the python version more enterprise-like. This is intended more as a parody of the styles of coding common in different languages.