Skip to content
Advertisement

Python – Flatten a dict of lists into unique values?

I have a dict of lists in python:

JavaScript

I want to turn it into a list of the unique values

JavaScript

I wrote a manual solution, but it’s a manual solution. I know there are more concise and more elegant way to do this with list comprehensions, map/reduce , itertools , etc. anyone have a clue ?

JavaScript

Advertisement

Answer

Double set comprehension:

Python 3:

JavaScript

Python 2:

JavaScript
User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement