Fizz Buzz
As seen on a thread on Hacker News about Fizz Buzz and “interesting” functional ways to solve it. Realized that there are many ways to boil the ocean, but this feels like a nice compromise between data/program separation and language.
Note this is using a “Bazz” variant of the FizzBuzz problem where Bazz is printed every 7 numbers.
1cases = [(3, "Fizz"), (5, "Buzz"), (7, "Bazz")]
2
3for i in range(110):
4 pr = ''.join([s * (i % m == 0) for m, s in cases])
5 print pr or i