4 ms·
I can't take a guide seriously when things like this are sprinkled all over it: return [x for x in items if x.endswith(".py")] if (r
by eugenekolo2 11y ago
I can't take a guide seriously when things like this are sprinkled all over it:
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 pyfiles
- pixelmonkey 11y agoIt's a fair point, but the style guide is meant to be illustrative. The 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.