python 3字典过滤器

我有字典:

tmpDict = {
'original': ['Locate inner shroud bushes onto variable vanes.'],'operation': ['locate'],'target': ['inner shroud bushes'],'targetState': ['onto variable vanes'],'referenceToSpecification': [None],'relation': [None],'operationmanner': [None],'aim': [None]
}

,我想对其进行过滤以删除“无”值。因此得到这个:

{
'original': ['Locate inner shroud bushes onto variable vanes.'],}

我尝试过:

tempDict = {k: v for k,v in tempDict.items() if v != None}

还有一些运气不好。

zswalkflower 回答:python 3字典过滤器

您的值是[None]而不是None。您应该改为测试[None]

tempDict = {k: v for k,v in tmpDict.items() if v != [None]}
本文链接:https://www.f2er.com/3150196.html

大家都在问