I mean this would remove False and None from a list though.
Also 0 and empty strings
People used to argue that Python was incredibly readable. Then I started seeing shit like this.
I think that Python has a bit of a ‘Microsoft Word’ thing on the go. You know how your own docs are completely editable and print fine, but everyone else’s are a complete fucking disaster and pressing a single key will screw up the formatting of the whole document? Your own Python code is full of sensible idioms and pragmatic naming conventions, but everyone else’s was plainly written while on mushrooms.
I’d say this is pretty readable
It jams far too much on one line. Break it up. It’s a mistake I see a lot on Python.
but if you do it as a for loop it would be slower
Unless you’re looping over more than a million elements, that’s a poor excuse.
or you’re doing this a million times
Python has great list comprehension. Too bad it’s incomprehensible to humans.
But seriously whoever writes those cool oneliners is a shitty programmer. Life is not code golf, fuck off with your smart ass.
What would be the alternative? (assuming that you want to do the loop yourself)
new_results = [] for result in results: if result: new_results.append(result) results = new_results
or else
for result in results: if not result: results.remove(result)
which doesn’t do the exact same thing.
Honestly, this list comprehension is much faster to read and quite easy to understand.
I think we could rename the “result” variable “x” or “res” and it would be less confusing though.