Four days after I started writing Python for business, I realized that I had never written FizzBuzz in Python, although I was able to implement business logic, so I tried it. Only try FizzBuzz, which is less readable, to get a feel for the detailed language specifications.
FizzBuzz In order to make it one-liner and as difficult to read as possible, I tried a ternary operator-like thing in the era when ternary operators and ternary operators did not exist.
[print(x) for x in [('Buzz' if i % 5 == 0 else 'Fizz' if i % 3 == 0 else i, 'FizzBuzz')[i % 15 == 0] for i in range(1, 101)]]
it is a good feeling!
By the way, it doesn't work in Python2 system because print is not a function. I wanted to write it so that it would work with Python 2 system, but I gave up because of lack of ability ...
Why don't you write the code whose readability is dead under the cause of understanding the language specifications?
that's all.
Recommended Posts