I've developed a program in python, organizing data in flattened dictionaries. As the size of the dict increases, the program becomes slower due to a intensive keys search. Looking at nested dictionaries structure, seems to me that a "hierarchical" approach may speed up the search of the keys. Am I wrong?
Is the nested dict:
nested_dict = { 'dictA': {'key_1': 'value_1', 'key_2': 'value_2'},
'dictB': {'key_3': 'value_3', 'key_4': 'value_4', 'key_5': 'value_5'},
...
'dictZ': {'key_m': 'value_m', 'key_n': 'value_n'}}
faster than the flattened dict:
dictionary = {'key_1': 'value_1',
'key_2': 'value_2',
...
'key_n': 'value_n'}
Edit: Added few code examples
Below a piece of the code generally I use. The Program is quite big, so there isn't a specific code to be evaluated
Assignment:
dictionary['key_1'] = dictionary2['key_a']
dictionary['key_3'] = dictionary2['key_a']*dictionary['key_4']
Conditional statement:
if( (0 == dictionary['key_1']) and
(dictionary2['key_b'] >= dictionary['key_3']) ):