Python3字典过滤器
我有字典:Python3字典过滤器,python,dictionary,filter,Python,Dictionary,Filter,我有字典: tmpDict = { 'original': ['Locate inner shroud bushes onto variable vanes.'], 'operation': ['locate'], 'target': ['inner shroud bushes'], 'targetState': ['onto variable vanes'], 'referenceToSpecification': [None], 'relation': [None], 'oper
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.'],
'operation': ['locate'],
'target': ['inner shroud bushes'],
'targetState': ['onto variable vanes'],
}
我试过:
tempDict = {k: v for k, v in tempDict.items() if v != None}
你的价值观是
[None]
而不是None
。您应该改为测试[None]
:
tempDict = {k: v for k, v in tmpDict.items() if v != [None]}
您的值是
[None]
不是None
。您应该改为测试[None]
:
tempDict = {k: v for k, v in tmpDict.items() if v != [None]}