【发布时间】:2017-06-23 19:01:36
【问题描述】:
我有两本词典:
dict1 = {'a': 1,
'b': 2,
'c': 3,
'd': 4,
'x': 5}
和
dict2 = {'a': 'start',
'b': 'start',
'c': 'end',
'd': 'end'}
我正在尝试创建一个新字典,将值start 和end 作为键映射到包含dict1 信息的字典,同时保留dict2 中不存在的那些作为键,例如:
dict3 = {'start': {'a': 1, 'b': 2},
'end': {'c': 3, 'd': 4},
'x': {'x': 5}
}
【问题讨论】:
标签: python dictionary