Skip to content

Instantly share code, notes, and snippets.

@hidsh
Created March 8, 2012 01:16
Show Gist options
  • Save hidsh/1997781 to your computer and use it in GitHub Desktop.
Save hidsh/1997781 to your computer and use it in GitHub Desktop.
python dictionary filter test
>>> dk = {'a':'0001', 'b':'0300', 'c':'0000', 'd':'0002', 'x':'0000'}
>>> dict((k,v) for k, v in dk.iteritems() if v=='0000')
{'x': '0000', 'c': '0000'}
>>> [k for k, v in dk.iteritems() if v=='0000']
['x', 'c']
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment