Best way to find unique items in a list
Timothy Grant
tjg at avalongroup.net
Thu Feb 24 15:44:33 EST 2000
maxm wrote:
> 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
>
> print Unique(['Max','Gitte','Magnus','Caroline','Clara','Max','Gitte'])
How about...
def Unique(theList):
uniqueList = []
for value in theList:
if value in uniqueList:
continue
uniqueList.append(value)
return uniqueList
--
Stand Fast,
tjg.
Chief Technology Officer tjg at exceptionalminds.com
Red Hat Certified Engineer www.exceptionalminds.com
Avalon Technology Group, Inc. (503) 246-3630
>>>>>>>>>>>>Linux...Because rebooting isn't normal<<<<<<<<<<<<
More information about the Python-list
mailing list