+1 vote
in Programming Languages by (9.6k points)
I have the following dictionary:

aa={'a':[1,2,3,4], 'b':[3,4,5], 'c':[1,4,5]}

I want to covert its list of values to a set so that I will have unique values. How can I do it?

Output should be {1, 2, 3, 4, 5}

1 Answer

+2 votes
by (59.8k points)
selected by
Best answer

Here is the one-liner pythonic way to get the set of values from the list of values of a dictionary.

>>> aa={'a':[1,2,3,4], 'b':[3,4,5], 'c':[1,4,5]}

>>> {v for _,vv in aa.items() for v in vv}

{1, 2, 3, 4, 5}