Implementation of certain tree based dictionaries in Python