I have a class that inherits from the dict class. In the example below, I define two keys 'x' and 'x2' with default value
class myClass(dict):
def __init__(self,*arg,**kw):
super(myClass, self).__init__(*arg, **kw)
self['x']=2
self['x2']=self['x']*self['x']
I want that they are linked in a way so that if I modify 'x', 'x2' is updated by x*x, and if I modify 'x2', then 'x' is updated to sqrt(x)
I found a post that explains a solution to do that for class attributes: In class object, how to auto update attributes?
However, I cannot find a way to twist this example to make it work for dictionary keys. Does anyone has a clue about how to do it?
Thanks!