Skip to content

Instantly share code, notes, and snippets.

@costa86
Last active February 19, 2023 21:29
Show Gist options
  • Save costa86/0e4ef0bc4bfae95d4bf344d65cfb993b to your computer and use it in GitHub Desktop.
Save costa86/0e4ef0bc4bfae95d4bf344d65cfb993b to your computer and use it in GitHub Desktop.
FizzBuzz with lambda and destructuring
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