【发布时间】:2022-03-24 15:56:20
【问题描述】:
我有一本如下形式的字典:
{"level": [1, 2, 3],
"conf": [-1, 1, 2],
"text": ["here", "hel", "llo"]}
我想过滤列表以删除索引i 处的每个项目,其中值"conf" 中的索引不是>0。
所以对于上面的dict,输出应该是这样的:
{"level": [2, 3],
"conf": [1, 2],
"text": ["hel", "llo"]}
因为conf 的第一个值不是> 0。
我尝试过这样的事情:
new_dict = {i: [a for a in j if a >= min_conf] for i, j in my_dict.items()}
但这仅适用于一键。
【问题讨论】:
标签: python dictionary