I'm using Python 3.8. If I want to get a unique set of values for an array of dictionaries, I can do the below
>>> lis = [{"a": 1, "b": 2}, {"a": 3, "b": 4}]
>>> s = set( val for dic in lis for val in dic.values())
>>> s
{1, 2, 3, 4}
However, how would I refine the above if I only wanted a unique set of values for the dictionary key "a"? In the above, the answer would be
{1, 3}
I'll assume that each dictionary in the array has the same set of keys.
You could simply do:
I hope I've understood what you are looking for. Thanks.