I have a nested dictionary of people and item ratings, with people as the key. people may or may not share items.
Example:
{
'Bob' : {'item1':3, 'item2':8, 'item3':6},
'Jim' : {'item1':6, 'item4':7},
'Amy' : {'item1':6,'item2':5,'item3':9,'item4':2}
}
I'm looking for the simplest way to flip these relations, and have a new nested dictionary with items as the key.
Example:
{'item1' : {'Bob':3, 'Jim':6, 'Amy':6},
'item2' : {'Bob':8, 'Amy':5},
'item3' : {'Bob':6, 'Amy':9},
'item4' : {'Jim':7, 'Amy':2}
}
What is the best way to do this? Is it possible with a comprehension?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…