DEV Community

Discussion on: [Challenge] 🐝 FizzBuzz without if/else

Collapse
 
codemouse92 profile image
Jason C. McDonald • Edited

Ironically, I have a Python-based solution for this as an example in my upcoming EuroPython 2020 presentation!

def fizz_buzz(max):
    return [
        "fizz" * (not n % 3) +
        "buzz" * (not n % 5)
        or str(n)
        for n in range(max + 1)
    ]

I picked up the * trick on a StackOverflow answer about this a while back, but I adapted it.