Steven Bethard [EMAIL PROTECTED] wrote:
...
I have a list[1] of objects from which I need to remove duplicates. I
have to maintain the list order though, so solutions like set(lst), etc.
will not work for me. What are my options? So far, I can see:
I think the recipe by that subject in
Hi,
I think your last solution is not good unless your list is sorted (in which
case the solution is trivial) since you certainly do have to see all the
elements in the list before deciding that a given element is not a duplicate.
You have to exhaust the iteratable before yielding anything.
Francis Girard wrote:
I think your last solution is not good unless your list is sorted (in which
case the solution is trivial) since you certainly do have to see all the
elements in the list before deciding that a given element is not a duplicate.
You have to exhaust the iteratable before
Francis Girard wrote:
Hi,
I think your last solution is not good unless your list is sorted
(in which
case the solution is trivial) since you certainly do have to see all
the
elements in the list before deciding that a given element is not a
duplicate.
You have to exhaust the iteratable
John Machin wrote:
So, just to remove ambiguity, WHICH one of the bunch should be
retained? Short answer: the first seen is what the proverbial man in
the street would expect
For my purposes, it doesn't matter which instance is retained and which
are removed, so yes, retaining the first one is
Steven Bethard wrote:
I'm sorry, I assume this has been discussed somewhere already, but I
found only a few hits in Google Groups... If you know where there's
a
good summary, please feel free to direct me there.
I have a list[1] of objects from which I need to remove duplicates.
I
have to
You could do it with a class, like this, I guess it is a bit faster
than option 1, although I'm no connaisseur of python internals.
-class uniquelist(list):
-def __init__(self, l):
-for item in l:
-self.append(item)
-def append(self, item):
-if item not in
Take a look at this recipe on ASPN:
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/204297
I think it might help.
Larry Bates
Steven Bethard wrote:
I'm sorry, I assume this has been discussed somewhere already, but I
found only a few hits in Google Groups... If you know where there's a
Carl Banks wrote:
from itertools import *
[ x for (x,s) in izip(iterable,repeat(set()))
if (x not in s,s.add(x))[0] ]
Wow, that's evil! Pretty cool, but for the sake of readers of my code,
I think I'll have to opt against it. ;)
STeVe
--
http://mail.python.org/mailman/listinfo/python-list
You could create a class based on a list which takes a list as
argument, like this:
-class uniquelist(list):
-def __init__(self, l):
-for item in l:
-self.append(item)
-
-def append(self, item):
-if item not in self:
-list.append(self, item)
-
-l =
Steven Bethard wrote:
I'm sorry, I assume this has been discussed somewhere already, but I
found only a few hits in Google Groups... If you know where there's a
good summary, please feel free to direct me there.
I have a list[1] of objects from which I need to remove duplicates. I
have to
11 matches
Mail list logo