How do I check all variables returned buy the functions exists

Robin Becker robin at reportlab.com
Wed Sep 20 03:46:00 EDT 2017


On 16/09/2017 01:58, Steve D'Aprano wrote:
........
> 
> If you want to test for None specifically:
> 
> if any(v is None for v in values):
>      print "at least one value was None"
> 
.......

for some reason that seems slow on my machine when compared with

if None in values:
    .....


> C:\usr\share\robin\pythonDoc>python -m timeit -s"values=(1,2,None)" "any(v is None for v in values)"
> 1000000 loops, best of 3: 0.62 usec per loop
> 
> C:\usr\share\robin\pythonDoc>python -m timeit -s"values=(None,2,None)" "any(v is None for v in values)"
> 1000000 loops, best of 3: 0.504 usec per loop
> 
> C:\usr\share\robin\pythonDoc>python -m timeit -s"values=(None,2,None)" "None in values"
> 10000000 loops, best of 3: 0.0309 usec per loop
> 
> C:\usr\share\robin\pythonDoc>python -m timeit -s"values=(1,2,None)" "None in values"
> 10000000 loops, best of 3: 0.097 usec per loop

it also seems a bit less obvious
-- 
Robin Becker




More information about the Python-list mailing list