Unique Elements in a List
Aahz
aahz at pythoncraft.com
Tue May 10 14:24:25 EDT 2005
In article <87psvzikjk.fsf at titan.staselog.com>,
Edvard Majakari <edvard+news at majakari.net> wrote:
>James Stroud <jstroud at mbi.ucla.edu> writes:
>>
>> from sets import Set
>>
>> data = [0.1,0.5,0.6,0.4,0.1,0.5,0.6,0.9]
>>
>> [x for x in Set(data) if data.count(x) == 1]
>
>Um.
>
>...I must have missed something, but I'll post nevertheless:
>
>wouldn't just
>
>[x for x in data if data.count(x) == 1]
>
>suffice? it is also "stable" preserving order of items. Lemme demo:
Only for small datasets -- this is an O(N^2) algorithm.
--
Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/
"And if that makes me an elitist...I couldn't be happier." --JMS
More information about the Python-list
mailing list