Skip to content

Instantly share code, notes, and snippets.

Embed
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))
@JonathanDagan

This comment has been minimized.

Copy link

@JonathanDagan JonathanDagan commented Sep 3, 2020

list comprehension verion:

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

also the:

str(i)

isn't really necessary

otherwise nice implementation

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.