The closest thing that comes to mind is a property, which automatically evaluates a function when read:
>>> class LenDict(dict):
... @property
... def len(self):
... return len(self)
...
>>> d=LenDict()
>>> d.len
0
>>> d[1]=2
>>> d.len
1
>>>
But IMHO this is no clearer than using len(d)
directly, and certainly not as efficient. It's also possible to place the hook the other way around by wrapping setitem.