3 ms·
Just for fun, another variant - separating logic from data and trying to be pretty stock python. cases = [(3, "Fizz"), (5, "Buzz"), (7, "Bazz")] for i
by koblas 14y ago
Just for fun, another variant - separating logic from data and trying to be pretty stock python.
cases = [(3, "Fizz"), (5, "Buzz"), (7, "Bazz")]
for i in range(110):
pr = ''.join([v[1] * (i % v[0] == 0) for v in cases])
print pr or i
- deadmansshoes 14y agoIt should be possible in a single line of Python.. pip install fizzbuzz And then: import fizzbuzz print fizzbuzz.fizzbuzz() Or for the second solution: print fizzbuzz.fizzbuzzbazz()
- jonp 14y agoA tweetable (140 character) single line of Python: print '\n'.join((lambda x:(''.join(x) if x else str(i)))([w+'zz' for (n,w) in ((3,'Fi'),(5,'Bu'),(7,'Ba')) if i%n==0]) for i in range(1,100))