Last active
February 19, 2023 21:29
-
-
Save costa86/0e4ef0bc4bfae95d4bf344d65cfb993b to your computer and use it in GitHub Desktop.
FizzBuzz with lambda and destructuring
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
def fizz_buzz(n: int = 15) -> list[str]: | |
fizz = lambda x: x % 3 == 0 | |
buzz = lambda x: x % 5 == 0 | |
result = [] | |
for i in range(1, n + 1): | |
if fizz(i) and buzz(i): | |
result.append("fizz_buzz") | |
continue | |
if buzz(i): | |
result.append("buzz") | |
continue | |
if fizz(i): | |
result.append("fizz") | |
continue | |
result.append(i) | |
return result |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment