Last active
July 31, 2020 03:15
-
-
Save shayelkin/5580497 to your computer and use it in GitHub Desktop.
Modulus-less fizzbuzz
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
from itertools import cycle, izip | |
def lazy_fizzbuzz(n): | |
""" | |
Returns iterator over fizzbuzz printout, starting at 1 and ending at n (inclusive) | |
""" | |
c = lambda i, s: cycle(([''] * i) + [s]) | |
fb = ('%s%s' % x for x in izip(c(2, 'Fizz'), c(4, 'Buzz'))) | |
return (x or y for (x,y) in izip(fb, xrange(1, n+1))) | |
print list(lazy_fizzbuzz(100)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
A port of the Haskell version (https://gist.github.com/shayelkin/5585299)