"praba kar" <[EMAIL PROTECTED]> schrieb im Newsbeitrag 
news:[EMAIL PROTECTED]
| Dear All,
|
|    I have doubt regarding sorting. I have a list
| that list have another list (eg)
|
| list = [[1234,'name1'],[2234,'name2'],[0432,'name3']]

-> Be careful, 0432 is octal notation for 282.
|
| I want to sort only numeric value having array field.
| How I need to do for that.

You may want use the decorate-sort-undecorate idiom.
I othere words, you isolate the index you want to sort by,
sort on the indices, than get rid of the indices again.

Something like:

def sortSeqOfSeqs(seq, idx):
    tmp = sorted([(elem[idx], elem) for elem in seq])
    return [elem[1] for elem in tmp]

seq = [[1234,'name1'],[2234,'name2'],[1432,'name3']]
print sortSeqOfSeqs(seq, 0)
# prints [[1234, 'name1'], [1432, 'name3'], [2234, 'name2']]
# Or to sort by the name index
print sortSeqOfSeqs(seq, 1)
# prints [[1234, 'name1'], [2234, 'name2'], [1432, 'name3']]


Is this what you we're looking for?

--

Vincent Wehren








|
| with regards
| Prabahar
|
|
|
|
|
|
| ________________________________________________________________________
| Yahoo! India Matrimony: Find your life partner online
| Go to: http://yahoo.shaadi.com/india-matrimony 


-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to