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
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
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
"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
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
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
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