Created
January 17, 2023 23:46
-
-
Save lonnen/f33f51be11460b87d7bbacd6425f5b5d to your computer and use it in GitHub Desktop.
my favorite implementation of 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 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