Re: unique-ifying a list

2009-08-09 Thread Simon Forman
On Aug 7, 4:53 pm, kj wrote: > Suppose that x is some list.  To produce a version of the list with > duplicate elements removed one could, I suppose, do this: > >     x = list(set(x)) > > but I expect that this will not preserve the original order of > elements. > > I suppose that I could write so

Re: unique-ifying a list

2009-08-08 Thread Paul Rubin
Dennis Lee Bieber writes: > Why bother with seen? The version with seen runs in linear time because of the O(1) set lookup. Your version runs in quadratic time. -- http://mail.python.org/mailman/listinfo/python-list

Re: unique-ifying a list

2009-08-08 Thread ryles
On Aug 7, 4:53 pm, kj wrote: > Suppose that x is some list.  To produce a version of the list with > duplicate elements removed one could, I suppose, do this: > >     x = list(set(x)) > > but I expect that this will not preserve the original order of > elements. > OrderedSet is most likely on the

Re: unique-ifying a list

2009-08-08 Thread Elias Fotinis (eliasf)
"kj" wrote: I suppose that I could write something like def uniquify(items): seen = set() ret = [] for i in items: if not i in seen: ret.append(i) seen.add(i) return ret But this seems to me like such a commonly needed operation that I find it hard to be

Re: unique-ifying a list

2009-08-07 Thread Gabriel Genellina
En Fri, 07 Aug 2009 17:53:10 -0300, kj escribió: Suppose that x is some list. To produce a version of the list with duplicate elements removed one could, I suppose, do this: x = list(set(x)) but I expect that this will not preserve the original order of elements. I suppose that I could

Re: unique-ifying a list

2009-08-07 Thread Jonathan Gardner
On Aug 7, 1:53 pm, kj wrote: > Suppose that x is some list.  To produce a version of the list with > duplicate elements removed one could, I suppose, do this: > >     x = list(set(x)) > > but I expect that this will not preserve the original order of > elements. > > I suppose that I could write so

unique-ifying a list

2009-08-07 Thread kj
Suppose that x is some list. To produce a version of the list with duplicate elements removed one could, I suppose, do this: x = list(set(x)) but I expect that this will not preserve the original order of elements. I suppose that I could write something like def uniquify(items): seen