kingthrillgore@lemmy.ml to 196@lemmy.blahaj.zone · 1 year agodoes this code run rulelemmy.mlimagemessage-square43fedilinkarrow-up1290arrow-down10
arrow-up1290arrow-down1imagedoes this code run rulelemmy.mlkingthrillgore@lemmy.ml to 196@lemmy.blahaj.zone · 1 year agomessage-square43fedilink
minus-squareInEnduringGrowStrong@sh.itjust.works@sh.itjust.workslinkfedilinkarrow-up58·1 year agoI mean this would remove False and None from a list though.
minus-squarebleistift2@feddit.delinkfedilinkEnglisharrow-up29·1 year agoAnd empty lists, tuples, dictionaries, sets, and strings
minus-squareunalivejoy@lemm.eelinkfedilinkEnglisharrow-up21·edit-21 year agoresults = list(filter(None, results))
minus-squareLostXOR@kbin.sociallinkfedilinkarrow-up4·1 year agoresults = [result for result in results if result != None]
minus-squareLostXOR@kbin.sociallinkfedilinkarrow-up3·1 year agoYou’re right, though IIRC there’s no functional difference when comparing to None (other than speed).
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).