I have a dictionary as:
default = {\'a\': [\'alpha\'], \'b\': [\'beta\',\'gamma\'], \'g\': []}
I wish to eliminate the empty values as:
You can use dict comprehension: -
>>> default = {'a': ['alpha'], 'b': ['beta','gamma'], 'g': []} >>> {key: value for key, value in default.iteritems() if value} {'a': ['alpha'], 'b': ['beta', 'gamma']}