Last active
July 17, 2018 14:56
-
-
Save lotusirous/acbef2f0178dfdc952cd4b4c142f13a5 to your computer and use it in GitHub Desktop.
Filter a dict by value in one line
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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