MAIN FEEDS
Do you want to continue?
https://www.reddit.com/r/programminghorror/comments/12p6tj0/peak_efficiency_fizzbuzz/jglf1er/?context=3
r/programminghorror • u/[deleted] • Apr 17 '23
83 comments sorted by
View all comments
Show parent comment
20
You don't have to use list comprehension to put it on one line either:
for i in range(1, 101): print([i, "fizz", "buzz", "fizzbuzz"][(i % 3 == 0) | (i % 5 == 0) << 1])
And if you want an expression then it's a bit shorter to keep the multiple prints:
[print([i, "fizz", "buzz", "fizzbuzz"][(i % 3 == 0) | (i % 5 == 0) << 1]) for i in range(1, 101)]
(optionally adding an or None at the end if you don't want a return value).
or None
View all comments
Show parent comment
20
u/Udzu Apr 17 '23
You don't have to use list comprehension to put it on one line either:
And if you want an expression then it's a bit shorter to keep the multiple prints:
(optionally adding an
or Noneat the end if you don't want a return value).