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.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…