+1 vote
in Programming Languages by (77.8k points)
I want a create a set using the values of the following dictionary. How can I do it Pythonically?

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

The result should be {1, 2, 3, 4, 5}

1 Answer

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

Here is the one-liner code that you can use to create the set using the values of a dictionary:

>>> aa = {'a': [1, 2, 3, 4], 'b': [3, 4, 5], 'c': [1, 4, 5]}
>>> {value for values_list in aa.values() for value in values_list}
{1, 2, 3, 4, 5}
>>>


...