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

<- View Parent
gigachad@sh.itjust.works ⁨6⁩ ⁨days⁩ ago

I am not saying it’s better, just that I don’t like the proposed way :) I would argue that being “pythonic” has even less value than the Zen, which I quoted because it’s true, not because it is some strict rule (which it isn’t anyway).

You could argue I also need to write that extra code for the if not case, as I explicitly have to check if it is None if my program somewhere further down expects only lists.

Hunting for those sweet milliseconds is a popular game in the Python community ;) if this mechanism is that important for your program, you should definitely use it, I would do as well!

source
Sort:hotnewtop