Very similar to this previous question but not quite they same. In that example, the question is essentially how to perform some function on the values of the 'inner' dictionary - but the keys of both outer and inner dicts stay the same. I want the values of the inner dict to become they keys of the new dict, and the have new values based on the old keys.
I have a 'nested' dictionary like this:
data = {
"A":{"X":1, "Y":2, "Z":3},
"B":{"X":4, "Y":5, "Z":6},
"C":{"X":7, "Y":8, "Z":9},
}
I want to create a new dictionary with the values of the inner dictionaries (i.e. the numbers) as the new keys, with new values based on concatenating the keys of the outer and inner dictionaries:
new_data = {
1:"AX",
2:"AY",
3:"AZ",
4:"BX",
5:"BY",
6:"BZ",
7:"CX",
8:"CY",
9:"CZ",
}
Based on the linked post, I tried
data = {inner_v: outer_k + inner_k for inner_k, inner_v in outer_v.items() for outer_k, outer_v in outer_dict.items()}
But I get an error saying outer_v is not defined