【发布时间】:2020-05-09 19:29:11
【问题描述】:
我想从字典中删除重复的键“John Doe”。
字典
info = [{"author": "John Doe", "book": {"title": "Getting started with Golang", "rating": 4.2, "category": "programming"}},
{"author": "John Doe", "book": {"title": "Best practices with Reactjs", "rating": 4.4, "category": "front-end"}}]
我希望结果看起来像这样:
test = {info[0]["author"]: [info[0]["book"], info[1]["book"]]}
我的尝试,除了这会删除整个第二个字典。
aList = {}
final = []
for i in info:
for values in i.values():
if values not in aList.values():
aListi["author"] = values
print(aList)
我们将不胜感激!
【问题讨论】:
标签: python python-3.x dictionary key key-value