请提示我,如何使用Python规范这个JSON文件?
这个问题与previous有关。
当前的JSON包含:
{
"total_stats": [
{
"domain": "domain.com",
"uptime": "100"
},
{
"domain": "domain.com",
"threats": "345.01111783804436"
}
]
}可取的
{
"total_stats": [
{
"domain": "domain.com",
"uptime": "100",
"threats": "345.01111783804436"
}
]
}发布于 2022-11-07 14:23:42
如果要根据可以使用的"domain"键合并字典(注意:如果字典有公用键,则将使用最后一个字典值):
dct = {
"total_stats": [
{"domain": "domain.com", "uptime": "100"},
{"domain": "domain.com", "threats": "345.01111783804436"},
]
}
out = {}
for d in dct["total_stats"]:
out.setdefault(d["domain"], {}).update(d)
dct["total_stats"] = list(out.values())
print(dct)指纹:
{
"total_stats": [
{
"domain": "domain.com",
"uptime": "100",
"threats": "345.01111783804436",
}
]
}https://stackoverflow.com/questions/74347818
复制相似问题