Py学习  »  Python

比较python中字典列表中的值

AlphabetSoup • 4 年前 • 1867 次点击  

我有一组两种模式的字典,比如 {"Id": 1, "title":"example"} {"Id": 1, "location":"city"} .我想把这两个结合起来 {"Id": 1, "title":"example", "location":"city"} ,适用于所有带有 Id 这是一场比赛。在这种情况下,该组由100个项目中的200个项目组成 title s和100 location 一切都好吗 身份证件 从0到99。我想退回100本合并字典的清单。

可能如下所示:

def ResultHandler(extractedResult: list):
    jsonObj = {}
    jsonList = []
    for result in extractedResult:
        for key, val in result.items():
            #this works if its hardcoded val to a number...
            if key == "Id" and val == 1:
                jsonObj.update(result)
    jsonList.append(jsonObj)
    return jsonList
Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/130562
文章 [ 5 ]  |  最新文章 4 年前