[Tutor] Sorting a list of lists aka nested lists
Jim Roush
ja_roush at mminternet.com
Sat Aug 13 23:03:50 CEST 2005
Danny Yoo wrote:
>On Sat, 13 Aug 2005, Jim Roush wrote:
>
>
>
>>I have a python script that creates a list of lists like so:
>>
>> Quant.append( [ db_ticker, stock_close, MTD, 0, QTD, 0, YTD, 0, 0, 0 ] )
>>
>>After Quant is created, I want to sort it by MTD. If I use a simple
>>Quant.sort(), I assume its going to sort by 'db_ticker' which is not
>>what I want.
>>
>>I've been trying to figure out how to use the cmp() in a list sort
>>method and I have failed to understand.
>>
>>
>
>
>Hi Jim,
>
>AMK has written a nice mini-tutorial on how to use a list's sort()
>effectively:
>
> http://www.amk.ca/python/howto/sorting/sorting.html
>
>Does his tutorial make sense, or are there parts in there that are
>baffling? Please feel free to ask questions on it, and we'll try to help.
>
>
>
>
>
>
I actually saw this page this morning, which leads me to believe what I
want is something like:
Quant.sort(lambda x, y: x-y)
except how does x and y relate to the list of lists I created?
--
No virus found in this outgoing message.
Checked by AVG Anti-Virus.
Version: 7.0.338 / Virus Database: 267.10.8/71 - Release Date: 8/12/2005
More information about the Tutor
mailing list