check if bytes is all nulls

Steven D'Aprano steve+comp.lang.python at pearwood.info
Sun Apr 1 21:13:49 EDT 2018


On Sun, 01 Apr 2018 19:14:05 +0000, Arkadiusz Bulski wrote:

> Thanks,
> timeit gives `not any(key)` same performance as `sum(key)==0`.


Have you considered what happens when the key is *not* all zeroes?

key = b'\x11'*1000000

any(key) bails out on the first byte. sum(key) has to add a million 
values.




-- 
Steve




More information about the Python-list mailing list