I have a Python class Cthat should have two pseudo dict aand b. The term pseudo-dicts means that dictionaries do not actually exist and that they are βrecountedβ every time the key is accessed.
In pseudocode, it will 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 aand b, but since both have just a few short methods, I wonder if there is a more elegant and compact way to do this.
user141335
source
share