Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
203 views
in Technique[技术] by (71.8m points)

Change order of indices for dictionary of dictionaries in Python

EDIT: As suggested in the comments, I re-asked this question in Code Review, see here.


I am working with complex data sets in Python and I store the data in dictionaries. Since there are many variables I have many "indented dictionaries" with up to 4 indices of the form

data[key1][key2][key3][key4] = a_float_number

and these key_i can be anything from strings to floats. How can I easily rearrange this dictionary such that two of the keys are swapped? For example I want to change it to:

data_rearranged[key3][key2][key1][key4] == a_float_number

Currently I am doing this with for loops but it's a pain. Probably there is a better way of doing this, or my suspect is that there is a better data container that does not have this problem.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...