What is the right way to forming in-memory table in python with direct lookups for rows and columns.I thought of using dict of dicts this way,
class Table(dict):
def __getitem__(self, key):
if key not in self:
self[key]={}
return dict.__getitem__(self, key)
table = Table()
table['row1']['column1'] = 'value11'
table['row1']['column2'] = 'value12'
table['row2']['column1'] = 'value21'
table['row2']['column2'] = 'value22'
>>>table
{'row1':{'column1':'value11','column2':'value12'},'row2':{'column1':'value21','column2':'value22'}}
I had difficulty in looking up for values in columns.
>>>'row1' in table
True
>>>'value11' in table['row1'].values()
True
Now how do I do lookup if 'column1' has 'value11'
Is this method of forming tables wrong?Is there a better way to implement such tables with easier lookups?.Thanks