293
you are viewing a single comment's thread
view the rest of the comments

I mean this would remove False and None from a list though.

[-] lugal@sopuli.xyz 38 points 1 year ago

Also 0 and empty strings

[-] bleistift2@feddit.de 31 points 1 year ago

And empty lists, tuples, dictionaries, sets, and strings

[-] joyjoy@lemm.ee 24 points 1 year ago* (last edited 1 year ago)

results = list(filter(None, results))

[-] LostXOR@kbin.social 4 points 1 year ago

results = [result for result in results if result != None]

[-] naught@sh.itjust.works 22 points 1 year ago
[-] LostXOR@kbin.social 3 points 1 year ago

You're right, though IIRC there's no functional difference when comparing to None (other than speed).

[-] AVincentInSpace@pawb.social 9 points 1 year ago

Yes there is. One invokes __ne__ on the left hand side, the other performs an identity comparison.

this post was submitted on 22 Nov 2023
293 points (100.0% liked)

196

16501 readers
2229 users here now

Be sure to follow the rule before you head out.

Rule: You must post before you leave.

^other^ ^rules^

founded 1 year ago
MODERATORS