kingthrillgore@lemmy.ml to 196@lemmy.blahaj.zone · 11 months agodoes this code run rulelemmy.mlimagemessage-square44fedilinkarrow-up1295arrow-down10
arrow-up1295arrow-down1imagedoes this code run rulelemmy.mlkingthrillgore@lemmy.ml to 196@lemmy.blahaj.zone · 11 months agomessage-square44fedilink
minus-square[email protected]@sh.itjust.workslinkfedilinkarrow-up59·11 months agoI mean this would remove False and None from a list though.
minus-squarebleistift2@feddit.delinkfedilinkEnglisharrow-up31·11 months agoAnd empty lists, tuples, dictionaries, sets, and strings
minus-squareunalivejoy@lemm.eelinkfedilinkEnglisharrow-up24·edit-211 months agoresults = list(filter(None, results))
minus-squareLostXOR@kbin.sociallinkfedilinkarrow-up4·11 months agoresults = [result for result in results if result != None]
minus-squareLostXOR@kbin.sociallinkfedilinkarrow-up3·11 months agoYou’re right, though IIRC there’s no functional difference when comparing to None (other than speed).
minus-squareAVincentInSpace@pawb.sociallinkfedilinkEnglisharrow-up9·11 months agoYes there is. One invokes __ne__ on the left hand side, the other performs an identity comparison.
I mean this would remove False and None from a list though.
Also 0 and empty strings
And empty lists, tuples, dictionaries, sets, and strings
results = list(filter(None, results))
results = [result for result in results if result != None]
Should be
is not None
(:You’re right, though IIRC there’s no functional difference when comparing to None (other than speed).
Yes there is. One invokes
__ne__
on the left hand side, the other performs an identity comparison.