python Get the unique values from a dictionary

python, python-2.7, python-3.x

Solution

It is not clear why you are mapping to single-item lists as values, but you can use a list comprehension to extract the elements.

foobar = {320: [167], 316: [0], 319: [167], 401: [167], 319: [168], 380: [167], 265: [166]}
print list(set([x[0] for x in foobar.values()]))

If you start out by mapping directly to values though, the code can be much simpler.

foobar = {320: 167, 316: 0, 319: 167, 401: 167, 319: 168, 380: 167, 265: 166}
print list(set(foobar.values()))

Problem

I want to get the unique values from my dictionary. Input: ``` {320: [167], 316: [0], 319: [167], 401: [167], 319: [168], 380: [167], 265: [166]} ``` Desired Output: ``` [167,0,168,166] ``` My code : ``` unique_values = sorted(set(pff_dict.itervalues())) ``` But I'm getting this error : `TypeError: unhashable type: 'list'`

Original source