-3

我有一个字典:

a = {<Object: object1>: [{'one': 25, 'two': 3}, {'one': 18, 'two': 2}, {'one': 10, 'two': 1}], <Object: object2>: [{'one': 25, 'two': 4}, {'one': 18, 'two': 2}], <Object: object3>: [{'one': 35, 'two': 5}, {'one': 15, 'two': 2}]}

有人可以解释一下如何用键“二”将每个项目与键“一”分开,以像下面这样做 dict 吗?

b = {<Object: object1>: [{8.3}, {9}, {10}], <Object: object2>: [{6.25}, {9}], <Object: object3>: [{7}, {7.5}]}
4

1 回答 1

0
a = {'o1': [{'one': 25, 'two': 3}, {'one': 18, 'two': 2}, {'one': 10, 'two': 1}],
     'o2': [{'one': 25, 'two': 4}, {'one': 18, 'two': 2}],
     'o3': [{'one': 35, 'two': 5}, {'one': 15, 'two': 2}]}

b = dict(((k, [1.0*x['one']/x['two'] for x in v]) for k, v in a.items()))
于 2013-11-09T03:01:11.700 回答