Well the approach above won’t work as written - the expression dict[key].description gets .description from dict[key], which is
the value stored. And the assignment likewise tries to set a .description attribute on the value.
Your most direct approach is to make a little class with both a dict
for the dict itself, and another dict for the descriptions (or a
dict-of-dicts if you wanted more things than just the description).
Untested incomplete example:
class DescribedDict:
def __init__(self):
self.dict = {}
self.descriptions = {}
You’d need to fill it out with the mapping methods so that they went
through to the .dict. Then you could just access the .descriptions
internal dict for the descriptions.
You can make the above less burdensome by subclassing dict directly:
class DescribedDict(dict):
which makes it all work directly and you’d just need to add the .descriptions attribute in __init__. It isn’t generally recommended
to subclass the builtin types because they have some weirdnesses, but in
this case it work just fine.