Real sugar syntax in Python?
The idea of sugar syntax is to provide an easier way to read and write code, but at some point, we lost the purpose.
In Python is easier to code using fancy methods to simplify our logic in one line or one instruction but we compromised the readability of our code. Remember, we are not alone, we usually work in teams and it is important to keep that in mind and avoid any complexity for the next person is going to read and modify our code.
Here you can find an example in which we want to filter from a payload all laptops with Ryzen processor and 16GB of memory.
NOTE: We are not taking into consideration performance (Big O notation)
Giving this .json as input
- Sugar syntax, readability compromised
An alternative
2. Not Sugar syntax, but readable
All codes above do the same, they search in payload what we need, but each code has different ways to read, probably, there are some people that doesnt understand the first two, but last one.
All in life are decisions, we can write short lines of code, but sacrificing readability, or we can increase the lines and ensuring readability for the rest of the team.
Is your call, choose what is better for you and your team.
End.