如何删除列表字典中的列表条目?

时间:2016-02-22 17:02:27

标签: list dictionary python-3.4

我似乎无法遍历字典中的列表。

data={}
data['people']=[]
data['people'].append({'Name':'Michael'})
data['people'].append({'Name':'Paul'})

for idx, val in data['people']:
    if val == {'Name':'Michael'}:del data['people'][idx]

ValueError:解包需要多于1个值

1 个答案:

答案 0 :(得分:2)

这就是你想要的:

data={}
data['people']=[]
data['people'].append({'Name':'Michael'})
data['people'].append({'Name':'Paul'})

for i in data['people']:
    if i == {'Name':'Michael'}:
        data['people'].remove(i)