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
--
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
You could use:
B=list(set(A)).sort()
Hope that helps.
T
--
http://mail.python.org/mailman/listinfo/python-list
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
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
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))
--
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
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
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
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
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
--
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
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
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
14 matches
Mail list logo