如果其中一个键中有字符,如何删除JSON中列表的字典:
for i in data:
results = i["results"]
if not results == []:
for x in results:
price_str = x["price_str"]
if "await" in price_str:
results.remove(x)
我的意见:
"results": [{
"price_str": "results awaited",
"marque": "samsung"
},
{
"price_str": "sold",
"marque": "apple"
}]
我想要的输出:
"results":[{
"price_str": "sold",
"marque": "apple"
}]
迭代时从列表中删除元素的正确方法是迭代列表的副本:这样做不会得到意外的结果,因为您没有编辑正在迭代的列表。你知道吗
你也可以试试这个
y将具有已筛选的项目列表。如果你想的话,以后你可以把它重新分配到字典里。你知道吗
试试这个:
相关问题 更多 >
编程相关推荐