Created
July 12, 2019 11:35
-
-
Save remorses/9d2e227f5bcae41a466dbe07afe71b55 to your computer and use it in GitHub Desktop.
set of dictionaries in python
This file contains 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
l = [ | |
{ | |
'a': 1, | |
'b': 1, | |
}, | |
{ | |
'a': 2, | |
'b': 1, | |
}, | |
{ | |
'a': 3, | |
'b': 0, | |
}, | |
{ | |
'a': 3, | |
'b': 2, | |
}, | |
] | |
def dicts_set(dict_list, unique_props): | |
unique_identifier = lambda d: tuple([d.get(s) for s in unique_props]) | |
return list({unique_identifier(d): d for d in dict_list}.values()) | |
print(dict_set(l, ['a',])) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment