小编Aus*_*s10的帖子

将列表元素移动到词典

我有名字存储在列表中 ['Bob', 'Matt', 'Tim']

我正在尝试迭代列表并将名称添加到字典中.我想让它通过并将每个名字添加到自己的字典中

{first name : 'Bob'} {first name : 'Matt'} {first name : 'Tim'}
Run Code Online (Sandbox Code Playgroud)

这就是我想要使用的

names = {}

i = 0
while i < (len(first_names)):
    names.update(first_names[i])
    i += 1
Run Code Online (Sandbox Code Playgroud)

但我一直收到错误信息

ValueError: dictionary update sequence element #0 has length 1; 2 is required
Run Code Online (Sandbox Code Playgroud)

python dictionary list

-1
推荐指数
1
解决办法
76
查看次数

标签 统计

dictionary ×1

list ×1

python ×1