I usually do it by sorting the list and then scanning in the obvious
way, moving stuff down, and doing a single del operation at the end.
--
http://mail.python.org/mailman/listinfo/python-list
Marc Christiansen wrote:
Michael Spencer <[EMAIL PROTECTED]> wrote:
Nice. When you replace None by an object(), you have no restriction on
the elements any more:
Thanks for the suggestion, Marc.
Note that if there is no need to access the middle of the collection, then the
implementation is simpl
Michael Spencer <[EMAIL PROTECTED]> wrote:
Nice. When you replace None by an object(), you have no restriction on
the elements any more:
> Here's something to work with:
>
> class OrdSet(object):
> def __init__(self, iterable):
> """Build an ordered, unique collection of hashable ite
Delaney, Timothy C (Timothy) wrote:
Diez B. Roggisch wrote:
This is actually one thing that Java 1.5 has that I'd like to see in
Python - the LinkedHashSet and LinkedHashMap. Very useful data
structures.
Implementing these is fairly simple.
There are two Ordered Dictionary recipes in the cookbook a
Delaney, Timothy C (Timothy) wrote:
I've proposed this on python-dev, but the general feeling so far is
against it. So far the only use case is to remove duplicates without
changing order, and there are iterator-based solutions which would
normally be preferable.
I've needed a dict that would itera
Delaney, Timothy C (Timothy) wrote:
Michael Hoffman wrote:
For those who don't know, these implement a hash set/map which
iterates in the order that the keys were first added to the set/map.
I would love to see such a thing.
I've proposed this on python-dev, but the general feeling so far is
agai
Michael Hoffman wrote:
>>> For those who don't know, these implement a hash set/map which
>>> iterates in the order that the keys were first added to the set/map.
>
> I would love to see such a thing.
I've proposed this on python-dev, but the general feeling so far is
against it. So far the only
Steven Bethard wrote:
Delaney, Timothy C (Timothy) wrote:
For those who don't know, these implement a hash set/map which iterates
in the order that the keys were first added to the set/map.
I would love to see such a thing.
--
Michael Hoffman
--
http://mail.python.org/mailman/listinfo/python-list
The Cookbook features another interesting way to do it:
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/204297
--
mvh Björn
--
http://mail.python.org/mailman/listinfo/python-list
Steven Bethard wrote:
> Sounds like a good candidate for the collections module. Of course
> someone will need to implement it. ;)
I'll suggest it to Raymond ... ;)
Tim Delaney
--
http://mail.python.org/mailman/listinfo/python-list
Delaney, Timothy C (Timothy) wrote:
This is actually one thing that Java 1.5 has that I'd like to see in
Python - the LinkedHashSet and LinkedHashMap. Very useful data
structures.
For those who don't know, these implement a hash set/map which iterates
in the order that the keys were first added to
Diez B. Roggisch wrote:
> No. But I doubt that that is what you actually want, as listA will
> lose its order afterwards. Typically, something like that gets
> written like this:
This is actually one thing that Java 1.5 has that I'd like to see in
Python - the LinkedHashSet and LinkedHashMap. Ve
Max M wrote:
Eric Pederson wrote:
listA = list(Set(listA))
As of 2.4, set is a built-in type (2.3 had Set in module sets).
Another 2.4-ism is "sorted", which might very well be the way you
want to turn the set into a list:
listA = sorted(set(listA))
for this particular use, you can define sorte
> I'm going to go off on a tangent here and put in a plea for better
> variable
> naming. I'm looking at the above code, and can't figure out what "res" is
> supposed to be. Is it short for "rest", as in "the rest of the items"?
> Residual? Result? Restore? Any of these seems plausable. Not k
Title: RE: Best way to make a list unique?
[Max M]
#- >>> la = [1,2,3,4,3,2,3,4,5]
#- >>> from sets import Set
#- >>> sa = Set(la)
#- >>> for itm in sa:
#- ... print itm
Remember that in Python 2.4 you have ´´set´´ as a built-in data type:
"Diez B. Roggisch" <[EMAIL PROTECTED]> wrote:
> inserted = set()
> res = []
> for e in listA:
>if not e in inserted:
>res.append(e)
>inserted.add(e)
> listA = res
I'm going to go off on a tangent here and put in a plea for better variable
naming. I'm looking at the above code
Eric Pederson wrote:
I have
listA=[1,2,3,4,5,4,3,4,3,2,1]
and I want a list of only the unique members.
This seems inefficient, but works fine over my small sample lists:
listA=[a for a in set(listA)]
Is there a more efficient approach for cases where listA is large?
no. Even though the code
Eric Pederson wrote:
> I have
>
listA=[1,2,3,4,5,4,3,4,3,2,1]
>
> and I want a list of only the unique members.
>
> This seems inefficient, but works fine over my small sample lists:
>
listA=[a for a in set(listA)]
>
>
> Is there a more efficient approach for cases where listA is l
18 matches
Mail list logo