Python Dictionary Of Lists Of Dictionaries
I would like to be able to access data from a file, organizing them into a structure that I think should be a dictionary of lists of dictionaries, from what I understand, probably
Solution 1:
It seems like your schema is not ideal (although it is difficult to tell without understanding what you are storing). From looking at your data, KEY_1, R_1, and A_1 should be dictionaries rather than lists. By simplifying your structure, you will be to use [ID_FILE][KEY_1][R_2][A_3][P_2].b
Solution 2:
Thanks to Steven Rumbalski to indicate to me that tool, PyCifRW, but, answering to my topic's question, the needed structure is a dictionary of dictionaries, to achieve that gool:
r_list = ['20', '21']
dictionary = {}
r_dict = {}
a_dict = {}
for r in range(0,len(r_list)):
r = r_list[r]
dictionary['C'] = r_dict
r_dict[r] = a_dict
print dictionary
print dictionary['C']
"""output:
{'C': {'20': {}, '21': {}}}
{'20': {}, '21': {}}
equal to:
dictionary = {'C': {
'20': {},
'21': {}
}
}
"""
Post a Comment for "Python Dictionary Of Lists Of Dictionaries"