Possible Duplicate:
Pythonic Way to reverse nested dictionaries
I am having hard time trying to find a solution for this nested dictionary problem.
I found some itertools functions that could be used, but it is not clear to me as how to use it. any help on this front would be great
input = { "a" : { "x": 1, "y": 2 },
"b" : { "x": 3, "z": 4 } }
output = {'y': {'a': 2},
'x': {'a': 1, 'b': 3},
'z': {'b': 4} }
A simplistic way using
dict.setdefault:out: