In programming, certain dictionary-based data structures are very useful and important. For example:
Revision dictionary:Revision dictionary is a sub-type of dictionary that keeps keys sorted in the order of last modification. It is commonly used in cache handling which remembers most recently used items.
Default dictionary:Default dictionary can return a default element when the dictionary is accessed with a key that is not present in the dictionary. It already has an implementation in
collections.defaultdict
.Infinite default dictionary:An infinite default dictionary can be accessed with infinitely layer of nested recursion, e.g.,
dct[person_name][gender], dct[company_name][employees]
, it can be used to create dynamic data structures, or even modeling file-system structures.
So my question is that: in Python, is it possible to write a dictionary that has all the 3 features, i.e., an infinite default revision dictionary? In particular, one can specify options during creation, e.g., whether the items should be sorted in the order of insertion, or keys' order, or revision order. And how to implement if possible?
It would be very cool if future-version Python has a built-in Dictionary class that supports all of these features and options.