by eugenekolo2 · 10y ago · 0 comments
return [x
for x in items
if x.endswith(".py")]
if (response and
"data" in response and
response["data"]):
return response["data"]
Just use 2 lines instead of using valuable horizontal lines, and make the code harder to read.ex:
pyfiles = [x for x in items if x.endswith(".py")]
return pyfilesThe former example is indented the way longer lines might very well be e.g. if your filter clause were a 2-part bool, you might not be able to fit it in a one-liner. The indentation also clarifies the difference between it and the imperative example above it.
The latter example is a rewrite of code written with 2 nested if statements, so the indentation serves to show that now the two nested statements were incorporated into the bool evaluation. If I made it a one-liner, someone might make the argument that the nested version is "more readable", but as written all you can say is that the single-if version is "less nested", which is the point I was trying to get across.