Skip to content

Instantly share code, notes, and snippets.

@uppfinnarjohnny
Created October 6, 2011 19:03
Show Gist options
  • Select an option

  • Save uppfinnarjohnny/1268311 to your computer and use it in GitHub Desktop.

Select an option

Save uppfinnarjohnny/1268311 to your computer and use it in GitHub Desktop.
pick_by_keys()
def pick_by_keys(d, ks):
return dict((k, v) for k, v in d.iteritems() if k in ks)
d = {
'hello': 'world',
'foo': 'bar',
'romeo': 'juliet',
'alice': 'bob'
}
r = pick_by_keys(d, ('hello', 'alice'))
print r
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment