I have a Python class C
which should have two pseudo-dict
s a
and b
. The term pseudo-dicts means that the dictionaries don't actually exist and that they are “recomputed” each time a key is accessed.
In pseudocode this would look like this:
class C:
def a.__getitem__(self, key):
return 'a'
def b.__getitem__(self, key):
return 'b'
>>> c = C()
>>> c.a['foo']
'a'
>>> c.b['bar']
'b'
I could implement a class for a
and b
, but since both have just a few short methods, I wonder whether there is a more elegant and compact way to do this.