Skip to content

Instantly share code, notes, and snippets.

@shayelkin
Last active July 31, 2020 03:15
Show Gist options
  • Save shayelkin/5580497 to your computer and use it in GitHub Desktop.
Save shayelkin/5580497 to your computer and use it in GitHub Desktop.
Modulus-less fizzbuzz
#!/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))
@shayelkin
Copy link
Author

shayelkin commented May 15, 2013

A port of the Haskell version (https://gist.github.com/shayelkin/5585299)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment