find all the unique elements in a python list
May 25th, 2006 by Lawrence David
say we have the python list:
>>x = [5,6,5]
to remove the duplications, use the following code snippet:
>>x_nodups = dict(map(lambda i: (i,1),x)).keys()
::thanks to walter underwood::
python 2.4 (i think) and up also has the set type:
>>> f = [1, 2, 3, 4, 5, 5, 5, 6]
>>> set(f)
set([1, 2, 3, 4, 5, 6])
>>> list(set(f))
[1, 2, 3, 4, 5, 6]
yea, just heard about that a week or two ago. thanks for posting that info!