class RecursiveDict(dict):
    """Implementation of perl's autovivification feature."""

def __missing__(self, key):
    value = self[key] = type(self)()
return value
How to change behavior of dict() for an instance