python dict() 将一个list中的dict的内容转成k: v的格式

发布时间 2023-12-14 16:02:30作者: bitterteaer
list_ = [
    {
        "id": "11",
        "name": "12",
        "other": "13"
    },
    {
        "id": "21",
        "name": "22",
        "other": "23"
    },
    {
        "id": "31",
        "name": "32",
        "other": "33"
    },
]
test = dict([(i["id"], i["name"]) for i in list_])
print(test)
{'11': '12', '21': '22', '31': '32'}