Comment on Python Performance: Why 'if not list' is 2x Faster Than Using len()

<- View Parent
gigachad@sh.itjust.works ⁨1⁩ ⁨day⁩ ago

But None has no len

if not foo:  

-> foo could be an empty list or None, it is ambiguous.

len(foo) will lead to an exception TypeError, I can cleanly catch that.

It suggests I deal with a boolean when that is not the case. Explicit is better than inplicit, and if not foo to check for an empty list may be pythonic, but it’s still implicit af

source
Sort:hotnewtop