a = OrderedDict([(14, (2361.42, 1339.25)), (15, (3581.08, 1427.08)), (16, (0, 4640.11)), (17, (0, 2667.36)), (18, (0, 1686.63))])
b = OrderedDict([(14, '03-31'), (15, '04-07'), (16, '04-14'), (17, '04-21'), (18, '04-28')])
我想将b中的值替换为b值和b值 我试过这个
dict((b[key], value) for (key, value) in a.items())
输出是
{'03-31': (2361.42, 1339.25), '04-07': (3581.08, 1427.08), '04-28': (0, 1686.63), '04-21': (0, 2667.36), '04-14': (0, 4640.11)}
我希望它为
OrderedDict([('03-31', (2361.42, 1339.25)), ('04-07', (3581.08, 1427.08)), (04-14', (0, 4640.11)), ('04-21', (0, 2667.36)), ('04-28', (0, 1686.63))])
答案 0 :(得分:3)
您可以改为使用OrderedDict
构造函数:
OrderedDict((b[key], value) for (key, value) in a.items())