DEV Community

loading...

Discussion on: Unconditional Challenge: FizzBuzz without `if`

Collapse
yujiri8 profile image
Ryan Westlund • Edited

How's this?

def fizzbuzz(n):
    d = {(0, 0): lambda _: 'FizzBuzz', (0, 1): lambda _: 'Fizz',
        (0, 2): lambda _: 'Fizz', (0, 3): lambda _: 'Fizz',
        (0, 4): lambda _: 'Fizz', (1, 0): lambda _: 'Buzz',
        (2, 0): lambda _: 'Buzz', (1, 1): lambda n: n,
        (2, 2): lambda n: n, (1, 2): lambda n: n,
        (2, 1): lambda n: n, (1, 3): lambda n: n,
        (2, 3): lambda n: n, (1, 4): lambda n: n,
        (2, 4): lambda n: n}
    return str(d[(n % 3, n % 5)](n))
Enter fullscreen mode Exit fullscreen mode
Thread Thread
kallmanation profile image
Nathan Kallman Author

Excellent! I think you've checked off all the boxes. Thanks for submitting!

Forem Open with the Forem app