use*_*689 1 python dictionary list python-2.7
例如我有dict python
dict = {'a': '1', 'b': '2', 'c': '3'}
Run Code Online (Sandbox Code Playgroud)
和数组
arr = ['4', '5', '6']
Run Code Online (Sandbox Code Playgroud)
我想在dict中添加顺序值数组
dict1 = {'a': '4', 'b': '5', 'c': '6'}
Run Code Online (Sandbox Code Playgroud)
请提出具体的解决方案.
>>> d = {'a': '1', 'b': '2', 'c': '3'}
>>> arr = ['4', '5', '6']
>>> dict(zip(sorted(d), arr))
{'a': '4', 'c': '6', 'b': '5'}
Run Code Online (Sandbox Code Playgroud)