[Tutor] List Dup-Elim Method?

Rob Andrews randrews@planhouse.com
Fri, 2 Feb 2001 15:00:14 -0600

I'm working on a similar problem, but more complicated and involving a
zillion real world variables.  I haven't fully worked it out yet, but here
are some thoughts that might help you out.

If the list isn't 200,000 items long or something, you can try a brute force
approach.  For each item of the list, compare the item to each other item,
deleting duplicates as you go, then drop a copy of that item into a new

Or, do the same thing, but instead of deleting the dupes as you go, move
them into a *dupes* list, and copy the first item into a new list.

if mylist[0:1] == mylist[1:2]:
    mylist[1:2] = []

This code compares an item in a list to the item next to it.  If the two
items are equivalent, the second item is essentially removed.

Hope this helps a bit,
Rob Andrews

> Is there an easy way to eliminate duplicate elements in a list?
> (A list method I missed, maybe?)
> Thanks!
> Curtis