get rid of duplicate elements in list without set

2009-03-20 Thread Alexzive
Hello there, I'd like to get the same result of set() but getting an indexable object. How to get this in an efficient way? Example using set A = [1, 2, 2 ,2 , 3 ,4] B= set(A) B = ([1, 2, 3, 4]) B[2] TypeError: unindexable object Many thanks, alex --

Re: get rid of duplicate elements in list without set

2009-03-20 Thread Albert Hopkins
On Fri, 2009-03-20 at 07:16 -0700, Alexzive wrote: Hello there, I'd like to get the same result of set() but getting an indexable object. How to get this in an efficient way? Example using set A = [1, 2, 2 ,2 , 3 ,4] B= set(A) B = ([1, 2, 3, 4]) B[2] TypeError: unindexable

Re: get rid of duplicate elements in list without set

2009-03-20 Thread thomasvang...@gmail.com
You could use: B=list(set(A)).sort() Hope that helps. T -- http://mail.python.org/mailman/listinfo/python-list

Re: get rid of duplicate elements in list without set

2009-03-20 Thread Albert Hopkins
On Fri, 2009-03-20 at 07:54 -0700, thomasvang...@gmail.com wrote: You could use: B=list(set(A)).sort() Hope that helps. Which will assign None to B. sorted(list(... or B.sort() is probably what you meant. -- http://mail.python.org/mailman/listinfo/python-list

Re: get rid of duplicate elements in list without set

2009-03-20 Thread Tino Wildenhain
thomasvang...@gmail.com wrote: You could use: B=list(set(A)).sort() Hope that helps. That would leave a B with value None :-) B=list(sorted(set(A)) could work. smime.p7s Description: S/MIME Cryptographic Signature -- http://mail.python.org/mailman/listinfo/python-list

Re: get rid of duplicate elements in list without set

2009-03-20 Thread MRAB
Tino Wildenhain wrote: thomasvang...@gmail.com wrote: You could use: B=list(set(A)).sort() Hope that helps. That would leave a B with value None :-) B=list(sorted(set(A)) could work. sorted() accepts an iterable, eg a set, and returns a list: B = sorted(set(A)) --

Re: get rid of duplicate elements in list without set

2009-03-20 Thread Paul McGuire
On Mar 20, 9:54 am, thomasvang...@gmail.com thomasvang...@gmail.com wrote: You could use: B=list(set(A)).sort() Hope that helps. T That may hurt more than help, sort() only works in-place, and does *not* return the sorted list. For that you want the global built-in sorted: data = map(int,6

Re: get rid of duplicate elements in list without set

2009-03-20 Thread Scott David Daniels
Alexzive wrote: I'd like to get the same result of set() but getting an indexable object. How to get this in an efficient way? Go look at Ray Hettinger's recently announced recipe for 'OrderedSet': http://code.activestate.com/recipes/576694/ --Scott David Daniels Scott,dani...@acm.org

Re: get rid of duplicate elements in list without set

2009-03-20 Thread Peter Otten
Alexzive wrote: I'd like to get the same result of set() but getting an indexable object. How to get this in an efficient way? Example using set A = [1, 2, 2 ,2 , 3 ,4] B= set(A) B = ([1, 2, 3, 4]) B[2] TypeError: unindexable object If the initial list is ordered or at least

Re: get rid of duplicate elements in list without set

2009-03-20 Thread Steven D'Aprano
On Fri, 20 Mar 2009 07:16:40 -0700, Alexzive wrote: Hello there, I'd like to get the same result of set() but getting an indexable object. How to get this in an efficient way? Your question is too open-ended. Do you want to keep the items in the original order? Are the items hashable? Do

Re: get rid of duplicate elements in list without set

2009-03-20 Thread Michael Spencer
Alexzive wrote: Hello there, I'd like to get the same result of set() but getting an indexable object. How to get this in an efficient way? Example using set A = [1, 2, 2 ,2 , 3 ,4] B= set(A) B = ([1, 2, 3, 4]) B[2] TypeError: unindexable object Many thanks, alex --

Re: get rid of duplicate elements in list without set

2009-03-20 Thread grocery_stocker
On Mar 20, 8:34 am, Paul McGuire pt...@austin.rr.com wrote: On Mar 20, 9:54 am, thomasvang...@gmail.com thomasvang...@gmail.com wrote: You could use: B=list(set(A)).sort() Hope that helps. T That may hurt more than help, sort() only works in-place, and does *not* return the sorted

Re: get rid of duplicate elements in list without set

2009-03-20 Thread Aaron Brady
On Mar 20, 5:07 pm, Michael Spencer m...@telcopartners.com wrote: Alexzive wrote: snip And, if you really want, you can get the body of this into 1-line, noting that seen.add returns None, so the expression (item in seen or seen.add(item)) evaluates to True if item is in seen, or None (and

Re: get rid of duplicate elements in list without set

2009-03-20 Thread grocery_stocker
On Mar 20, 5:08 pm, grocery_stocker cdal...@gmail.com wrote: On Mar 20, 8:34 am, Paul McGuire pt...@austin.rr.com wrote: On Mar 20, 9:54 am, thomasvang...@gmail.com thomasvang...@gmail.com wrote: You could use: B=list(set(A)).sort() Hope that helps. T That may hurt more than