check if bytes is all nulls

Chris Angelico rosuav at gmail.com
Sun Apr 1 15:18:31 EDT 2018


On Mon, Apr 2, 2018 at 5:14 AM, Arkadiusz Bulski <arek.bulski at gmail.com> wrote:
> Thanks,
> timeit gives `not any(key)` same performance as `sum(key)==0`.

Are you timing these on ten-byte keys, or really large keys? For short
keys, just use whatever looks most elegant, and don't worry about
performance. If the key is actually megabytes long (which seems
unlikely, but you did mention it), do your timing tests on
megabyte-long keys.

ChrisA


More information about the Python-list mailing list