delete duplicates in list

Diez B. Roggisch deets_noospaam at web.de
Wed Oct 29 19:28:26 EST 2003


Hi,

> ...except it's not a LIST, which was part of the specifications given
> by the original poster.  It may, of course, be that you've read his
> mind correctly and that, despite his words, he doesn't really care
> whether he gets a list or a very different container:-).

You're right - mathematically. However, there is no such thing like a set in
computers - you always end up with some sort of list :)

So - he'll have a list anyway. But if it respects the order the list
parameter... <just checking, standby>

... nope:

>>> l = [1,2,3,2]
>>> import sets
>>> sets.Set(l)
Set([1, 2, 3])
>>> l = [2,1,2,3,2]
>>> sets.Set(l)
Set([1, 2, 3])

Which is of course reasonable, as the check for existence in the set might
be performed in O(ln n) instead of O(n).

Regards,

Diez




More information about the Python-list mailing list