A long and complex list comprehension definitely suffers from being too "smart" and thus ignores readability.
However, when it comes to a short for loop, i.e. generating a list of numbers from a range, no one should be using a regular for loop with append .
# This is way more readable
nums=[iforiinrange(10)]# This is less readable, IMO we shouldn't have to do this
nums=[]foriinrange(10):nums.append(i)
Throwing in a single conditional if (i.e. the grapes example in the post) is fine IMHO. It really depends on what you and your team agree on at the end of the day. Nothing beats a good consistency in a shared codebase.
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
A long and complex list comprehension definitely suffers from being too "smart" and thus ignores readability.
However, when it comes to a short for loop, i.e. generating a list of numbers from a
range
, no one should be using a regularfor
loop withappend
.Throwing in a single conditional
if
(i.e. thegrapes
example in the post) is fine IMHO. It really depends on what you and your team agree on at the end of the day. Nothing beats a good consistency in a shared codebase.