Python dictionary keys. “In” complexity
First, key in d.keys() is guaranteed to give you the same value as key in d for any dict d. And the in operation on a dict, or the dict_keys object you get back from calling keys() on it (in 3.x), is not O(N), it’s O(1). There’s no real “optimization” going on; it’s just that … Read more