Theodoros Emmanouilidis

Notes & Thoughts

Make A List With All Unique Items In A List Python

March31

This is just an one-liner, but very useful and convenient.

Suppose we have a python list

list=[1,4,2,3,4,5,6,3,2,6]

and we only want to return a list containing all unique elements of that list. We can use the “set” python command and construct a new list with all the unique elements of the original list.

list_unique(set(list))

print list_unique

[1,2,3,4,5,6]

Python rocks!!