Skip to content

Instantly share code, notes, and snippets.

@remorses
Created July 12, 2019 11:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save remorses/9d2e227f5bcae41a466dbe07afe71b55 to your computer and use it in GitHub Desktop.
Save remorses/9d2e227f5bcae41a466dbe07afe71b55 to your computer and use it in GitHub Desktop.
set of dictionaries in python
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