Skip to content

Instantly share code, notes, and snippets.

@lotusirous
Last active July 17, 2018 14:56
Show Gist options
  • Select an option

  • Save lotusirous/acbef2f0178dfdc952cd4b4c142f13a5 to your computer and use it in GitHub Desktop.

Select an option

Save lotusirous/acbef2f0178dfdc952cd4b4c142f13a5 to your computer and use it in GitHub Desktop.
Filter a dict by value in one line
d = {
'a' : 1,
'c': 1,
'b': 2
}
r = list(filter(lambda x: x[1] == 1, d.items())) # x is a tuple (k,v) == x[0], x[1]
print(r)
# result is [('a', 1), ('c', 1)]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment