Python将顺序值数组添加到dict

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)

请提出具体的解决方案.

vil*_*vil 5

>>> 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)

  • 如果海报没有改变他变量的名称,那么这将无效,因为他现在已经屏蔽了`dict`功能! (6认同)