【发布时间】:2022-01-11 17:03:19
【问题描述】:
假设我有一本这样的字典:
{
"test1": [{
"key1": "123",
"key2": "456",
"key3": null,
"key4": "Book1"
}, {
"key1": "123",
"key2": "456",
"key3": null,
"key4": "Book2"
}, {
"key1": "12311",
"key2": "45678",
"key3": null,
"key4": "Book1"
}, {
"key1": "123",
"key2": "456",
"key3": null,
"key4": "Book4"
}, {
"key1": "12322",
"key2": "45690",
"key3": null,
"key4": "Book1"
}
]
}
我想要的是另一个字典,其中我只有某些键等于某物的元素(在我的情况下,我想保留 key4 = Book1 的所有元素) 我怎样才能有另一个看起来像这样的字典:
{
"test1": [{
"key1": "123",
"key2": "456",
"key3": null,
"key4": "Book1"
}, {
"key1": "12311",
"key2": "45678",
"key3": null,
"key4": "Book1"
}, {
"key1": "12322",
"key2": "45690",
"key3": null,
"key4": "Book1"
}
]
}
【问题讨论】:
-
您需要编写代码,而您显然还没有尝试过。
-
嗨@ScottHunter,很抱歉,问题是我什至不知道从哪里开始,并不是我没有寻找解决方案,而是我发现的一切都没有解决我的问题跨度>
标签: python json python-3.x dictionary