Python 将列表元素移动到字典

Python 将列表元素移动到字典,python,list,dictionary,Python,List,Dictionary,我的名字存储在列表中['Bob'、'Matt'、'Tim'] 我正在尝试遍历列表并将名称添加到字典中。 我希望它仔细检查并将每个名字添加到自己的字典中 {first name : 'Bob'} {first name : 'Matt'} {first name : 'Tim'} 这就是我想用的 names = {} i = 0 while i < (len(first_names)): names.update(first_names[i]) i += 1 如果我没弄

我的名字存储在列表中['Bob'、'Matt'、'Tim']

我正在尝试遍历列表并将名称添加到字典中。 我希望它仔细检查并将每个名字添加到自己的字典中

{first name : 'Bob'} {first name : 'Matt'} {first name : 'Tim'}
这就是我想用的

names = {}

i = 0
while i < (len(first_names)):
    names.update(first_names[i])
    i += 1

如果我没弄错的话,你想要一份字典清单。在这种情况下,您可以执行以下操作:

nameList = ['john','rob','ben']
names =  [{'first name':i} for i in nameList]
其中:

[{'first name': 'john'}, {'first name': 'rob'}, {'first name': 'ben'}]
@loulou键在dict中是唯一的,因此它将只包含first_name中的最后一个元素,因为它将覆盖所有以前的名称。
[{'first name': 'john'}, {'first name': 'rob'}, {'first name': 'ben'}]