http://www.python.org/dev/peps/pep-3106/ (http://www.python.org/dev/peps/pep-3106/) has "pseudo-code to define the semantics":
class d_items:
def __init__(self, d):
self.__d = d
def __len__(self):
return len(self.__d)
def __contains__(self, (key, value)):
return key in self.__d and self.__d[key] == value
(etc.)
which suggests that that sort of optimisation (if you can really call it that) is what is in mind.
class d_items: def __init__(self, d): self.__d = d def __len__(self): return len(self.__d) def __contains__(self, (key, value)): return key in self.__d and self.__d[key] == value (etc.)which suggests that that sort of optimisation (if you can really call it that) is what is in mind.