Get unique values in List of Lists in python Get unique values in List of Lists in python python python

Get unique values in List of Lists in python


array = [['a','b'], ['a', 'b','c'], ['a']]result = {x for l in array for x in l}


You can use itertools's chain to flatten your array and then call set on it:

from itertools import chainarray = [['a','b'], ['a', 'b','c'], ['a']]print set(chain(*array))

If you are expecting a list object:

print list(set(chain(*array)))


array = [['a','b'], ['a', 'b','c'], ['a']]unique_values = list(reduce(lambda i, j: set(i) | set(j), array))