Best way to find unique items in a list
David Fisher
aiki108 at netscape.net
Thu Feb 24 05:51:56 EST 2000
Here's a quickie.
Def Unique(thelist):
uniquedict = {}
for i in thelist:
uniquedict[i] = 0
return uniquedict.keys()
Whether it's any faster i don't know.
david
>>>>>>>>>>>>>>>>>> Original Message <<<<<<<<<<<<<<<<<<
On 2/24/00, 4:31:32 AM, "maxm" <maxm at normik.dk> wrote regarding Best way
to find unique items in a list:
> I have written the following snippet to return a list of unique items
in
> another list. I just wondered if there was a smarter/faster way of
doing it?
> Anyone for a little brain gym?
> ------------------------------------------
> def Unique(theList):
> uniqueList = []
> OldValue = ''
> theList.sort()
> for value in theList:
> if OldValue != value:
> uniqueList.append(value)
> OldValue = value
> return uniqueList
More information about the Python-list
mailing list