3 ms·
By coincidence, I had just posted this earlier and updated it recently: print(" ".join("FizzBuzz" if i % 15 == 0 \ else "Buzz" if i % 5 == 0 else "Fizz" if
by vram22 8y ago
By coincidence, I had just posted this earlier and updated it recently:
print(" ".join("FizzBuzz" if i % 15 == 0 \
else "Buzz" if i % 5 == 0 else "Fizz" if i % 3 == 0 \
else str(i) for i in range(1, 101)))
From:
FizzBuzz in Python with nested conditional expressions and a generator expression:
https://jugad2.blogspot.com/2018/12/fizzbuzz-in-python-with-nested.html https://jugad2.blogspot.com/2018/12/fizzbuzz-in-python-with-...
Not claiming its the best in any way, just a way that I thought of.
- fouc 8y agoHe asked for beautiful. Like if you showed it to a non-programmer, would they think it's beautiful?
- vram22 8y ago1. So what? It's not always that case that people on HN reply (or must do so) to a question with an answer that exactly answers the question and nothing else. Diversions are fine and done a lot by users here, within reason. Otherwise these threads would look and sound like classes in logic or theorem proving, ha ha. We're humans here. 2. Why are you interpreting what he (or she) meant? Let them do it themselves. 3. I qualified my earlier comment as saying that it is not necessarily the best way - up front. 4. Beauty is in the eye of the beholder, and beholders vary a lot in their tastes, whether programmers or non-programmers. Like the "de gustibus" quote: https://en.wikipedia.org/wiki/De_gustibus_non_est_disputandum https://en.wikipedia.org/wiki/De_gustibus_non_est_disputandu... So chill, pal.