Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
FizzBuzz one-liner in Python 3
# Using a lambda function
print(list(map(lambda i: "Fizz"*(i%3==0)+"Buzz"*(i%5==0) or str(i), range(1,101))))
# Using a for loop
for i in range(1, 101): print("Fizz"*(i%3==0)+"Buzz"*(i%5==0) or str(i))
Copy link

khanfarhan10 commented Oct 3, 2021

print('\n'.join(list(map(lambda i: "Fizz"*(i%3==0)+"Buzz"*(i%5==0) or str(i), range(1,int(input())+1)))))

Copy link

Dummyapt commented Oct 17, 2021

print(list(map(lambda i: "Fizz" * (i % 3 == 0) + "Buzz" * (i % 5 == 0) or str(i), range(0, 101))))

Copy link

miron commented May 20, 2022

@JonathanDagan really nice! But this one actually works:

_=[print("Fizz"*(i%3==0)+"Buzz"*(i%5==0)or i)for i in range(1,101)]

You still get the output, but the print doesn't return the list with None values.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment