News for hackers. Stuff that matters.
Re:Try/Except vs. If in Dictionary Key Access Python Perform... by carapace on Saturday April 28, 2018 @12:03PM (#16948247)
However...

    $ python -m timeit -s "a={k:k  for k in range(10000)}" 'if 10001 in a:
       b=a[10001]
    else:
       pass'
    100000000 loops, best of 3: 0.0187 usec per loop
I gotta say, I didn't expect that. I thought the try..except.. for keys in the dict would be faster than this form. TIL

There are no comments on this comment yet.