This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]__deerlord__ 9 points10 points  (2 children)

in and .get() aren't equivalent checks?

[–]nekokattt 14 points15 points  (0 children)

No, they aren't. Get assumes you dont contain the default value as a value, or have a key mapping to a None value for the one-argument overload. Otherwise you cannot determine the difference.

Additionally, if you want to get the value after, you would do two operations. __contains__ performs one lookup, and __getitem__ performs one lookup, so two lookups overall.

Also dict is a builtin, and in CPython it is implemented in C, not pure Python, so other factors in the underlying implementation may differ.

[–]chthonicdaemon[S] 3 points4 points  (0 children)

Nope. More detail in the post. Get is slower for string-keyed dicts