Skip to content

Instantly share code, notes, and snippets.

@onlurking
Last active September 6, 2016 01:01
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save onlurking/55522246dd89df191a3c6ca126fc71fc to your computer and use it in GitHub Desktop.
Save onlurking/55522246dd89df191a3c6ca126fc71fc to your computer and use it in GitHub Desktop.
Python FizzBuzz Oneliners
for x in ("FizzBuzz" if num % 15 == 0 else "Fizz" if num % 3 == 0 else "Buzz" if num % 5 == 0 else num for num in range(1,101)): print(x)
for x in ["fizzbuzz" if not x % 15 else "buzz" if not x % 5 else "fizz" if not x % 3 else str(x) for x in range(100)]: print(x)
for x in [(not x % 3) * 'Fizz' + (not x % 5) * 'Buzz' or x for x in range(1, 101)]: print(x)
for x in (["fizzbuzz" if not x % 15 else "buzz" if not x % 5 else "fizz" if not x % 3 else str(x) for x in range(100)]): print(x)
', '.join(["fizzbuzz" if not x % 15 else "buzz" if not x % 5 else "fizz" if not x % 3 else str(x) for x in range(100)])
print('\n '.join([(not x % 3) * 'Fizz' + (not x % 5) * 'Buzz' or str(x) for x in range(1, 101)]))
', '.join([(not x % 3) * 'Fizz' + (not x % 5) * 'Buzz' or str(x) for x in range(1, 101)])
fizzbuzz = lambda x: list(map(lambda i: print(([i,"Fizz"],["Buzz","FizzBuzz"])[not i % 3][not i % 5]), range(0,x))) and None
fizzbuzz(100)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment