delete duplicates in list

Hannu Kankaanp?? hanzspam at yahoo.com.au
Thu Oct 30 03:20:41 EST 2003


"Diez B. Roggisch" <deets_noospaam at web.de> wrote in message news:<bnplva$g1s$07$1 at news.t-online.com>...
> 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 :)

Those are just implementation details. There could be a group of monkeys 
emulating Python under the hood and their implementation of a set
would be a neural network instead of any kind of sequence, but you
still wouldn't care as a programmer. The only thing that matters is,
if the interface stays same. Nope, the items in a set are no longer
accessible by their index (among other differences).

> So - he'll have a list anyway. 

So I can't agree with this. You don't know if his Python virtual machine
is a group of monkeys. Python is supposed to be a high level language.

> 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).

Actually the Set in sets module has an average lookup of O(1), worst
case O(n) (not 100% sure of worst case, but 99% sure). It's been
implemented with dictionaries, which in turn are hash tables.




More information about the Python-list mailing list