Removing values from dict in python
问题 This code: a = {'sd':{},'sdd':'','sadfas':None,'sadfa':'dsf'} a = dict((k, v) for k, v in a.iteritems() if v is not '' or v != {} or v is not None) print a prints: {'sdd': '', 'sadfas': None, 'sadfa': 'dsf', 'sd': {}} However, it does not remove all the type of values from dict which i need to remove. Why is that ? These values are removed if i do: a = {'sd':{},'sdd':'','sadfas':None,'sadfa':'dsf'} a=dict((k, v) for k, v in a.iteritems() if v is not '') a=dict((k, v) for k, v in a.iteritems()