In python 3, a dict (or anything implementing the collections.Mapping interface) has a keys()
method that returns a dict_keys
, which is iterable (yielding keys, as __iter__()
does) but can also respond to key in dict_keys
in O(1)
time (as __contains__
does).
But what else can dict_keys
do for me that __iter__
and __contains__
doesn't already?