Python likes giving lists.
Comment on Python Performance: Why 'if not list' is 2x Faster Than Using len()
sirber@lemmy.ca 11 months ago
How does Python know of it’s my list or not?
gargolito@lemm.ee 11 months ago
JasonDJ@lemmy.zip 11 months ago
if isinstance(mylist, list) and not mylistProblem solved.
Or
if not mylist # check if list is emptysirber@lemmy.ca 11 months ago
I think you missed the joke 😅
PattyMcB@lemmy.world 11 months ago
I thought it was funny!
gravitas_deficiency@sh.itjust.works 11 months ago
You’re checking if
mylistis falsey. Sometimes that’s the same as checking if it’s empty, if it’s actually a list, but that’s not guaranteed.JasonDJ@lemmy.zip 11 months ago
Doesn’t Python treat all empty iterables as false tho? This isn’t unique to python, is it? (though I’m not a programmer…just a dude who writes scripts every now and then)
BlackRoseAmongThorns@slrpnk.net 11 months ago
Not really, generators have weird truthiness, i don’t remember if they evaluate to true or false, but they cannot be checked for emptiness so they default to either always true or always false.
gravitas_deficiency@sh.itjust.works 11 months ago
My point is that the second statement you presented can have the effect of evaluating emptiness of a Sequence (note: distinct from an Iterable), but that only holds true if the target of the conditional IS a sequence. I’m underlining the semantic difference that was elided as a result of falsey evaluation.
2xsaiko@discuss.tchncs.de 11 months ago
Telemetry
jj4211@lemmy.world 11 months ago
else: # not my list, it is ourlist