我有一个词典:
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}]}
有人可以解释我如何用钥匙'一个'按键'一'来分隔每个项目,用下面这个词来做这个词吗?
b = {<Object: object1>: [{8.3}, {9}, {10}], <Object: object2>: [{6.25}, {9}], <Object: object3>: [{7}, {7.5}]}
答案 0 :(得分: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()))