I have a dict of lists in python:
content = {88962: [80, 130], 87484: [64], 53662: [58,80]}
I want to turn it into a list of the unique val
list(reduce(lambda a, b: a.union(set(b)), content.itervalues(), set()))
The lambda
turns the two input arguments into sets and unions them.
The reduce
will do a left fold over the list that is passed to it -- in this case, the lists that are the values of your dictionaries.
The reduce
will turn the result of this, which is a set
back into a list.
This can also be spelled:
list(reduce(lambda a, b: a | set(b), content.itervalues(), set()))