News for hackers. Stuff that matters.
Re:Python 3.11: “Zero cost” exception handling by stubish on Sunday October 10, 2021 @12:42AM (#28815795)
The second 'key in dict' option is not thread safe if dict_ is not local (another thread may delete the entry between the existence check and use). This is a good reason why the exception handling approach is a better idiom.

The exception handling approach may also be faster if your code cares (may, because I don't know if the cost of calculating the hash of "key" twice is cheaper than the exception handling overhead).

There are no comments on this comment yet.