cases = ( (3, 'Fizz'), (5, 'Buzz'), (7, 'Bazz'), (11, 'Boo'), (13, 'Blip'), ) for i in range(1, 101): out = [] for c in cases: if i % c[0] == 0: out.append(c[1]) if out: print ''.join(out) else: print i Edit: not to detract from the post's point, I think it's valid. Monoids are cool and all but simple counting arguments can take you a long, long, long, way when case analysis fails you.
for i in xrange(1, 101):
s = ""
if not i % 3:
s += "Fizz"
if not i % 5:
s += "Buzz"
if not i % 7:
s += "Bazz"
print s or i
Which can be shortened to: for i in xrange(1, 101):
s = ""
s += "Fizz" if i % 3 == 0 else ""
s += "Buzz" if i % 5 == 0 else ""
s += "Bazz" if i % 7 == 0 else ""
print s or i
Finishing the article inspired: print "\n".join(
"".join(filter(None, ("Fizz" if i % 3 == 0 else None,
"Buzz" if i % 5 == 0 else None,
"Bazz" if i % 7 == 0 else None)))
or str(i) for i in xrange(1, 101))