Skip to content

Instantly share code, notes, and snippets.

@lonnen
Created January 17, 2023 23:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lonnen/f33f51be11460b87d7bbacd6425f5b5d to your computer and use it in GitHub Desktop.
Save lonnen/f33f51be11460b87d7bbacd6425f5b5d to your computer and use it in GitHub Desktop.
my favorite implementation of fizzbuzz
#!/usr/bin/env python3
import itertools
fizzes = itertools.cycle(["", "", "Fizz"])
buzzes = itertools.cycle(["", "", "", "", "Buzz"])
fizzbuzzes = map(lambda x: "".join(x), zip(fizzes, buzzes))
def fizzbuzz(n):
return list(itertools.islice(fizzbuzzes, n))
# fizzbuzz(15)
# -> ['', '', 'Fizz', '', 'Buzz', 'Fizz', '', '', 'Fizz', 'Buzz', '', 'Fizz', '', '', 'FizzBuzz']
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment