Re: unique-ifying a list

2009-08-09 Thread Simon Forman
On Aug 7, 4:53 pm, kj no.em...@please.post 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

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

Re: unique-ifying a list

2009-08-08 Thread ryles
On Aug 7, 4:53 pm, kj no.em...@please.post 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

Re: unique-ifying a list

2009-08-08 Thread Paul Rubin
Dennis Lee Bieber wlfr...@ix.netcom.com 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

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

Re: unique-ifying a list

2009-08-07 Thread Jonathan Gardner
On Aug 7, 1:53 pm, kj no.em...@please.post 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

Re: unique-ifying a list

2009-08-07 Thread Gabriel Genellina
En Fri, 07 Aug 2009 17:53:10 -0300, kj no.em...@please.post 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