Re: [Tutor] Sorting a list of lists aka nested lists

2005-08-19 Thread Kent Johnson
mailing list wrote: > No-one's mentioned a Schwartzian Transform yet ; ) because it's obsoleted by the key parameter to sort... > > > > On 8/15/05, Kent Johnson <[EMAIL PROTECTED]> wrote: > >>[EMAIL PROTECTED] wrote: >> >>>Note that in Python2.4+, you can use key= instead: >>> >>>def sortKey

Re: [Tutor] Sorting a list of lists aka nested lists

2005-08-19 Thread mailing list
No-one's mentioned a Schwartzian Transform yet ; ) On 8/15/05, Kent Johnson <[EMAIL PROTECTED]> wrote: > [EMAIL PROTECTED] wrote: > > Note that in Python2.4+, you can use key= instead: > > > > def sortKey(lst): > > return lst[2] > > Quant.sort(key=sortKey) > > > > This is more effient than spe

Re: [Tutor] Sorting a list of lists aka nested lists

2005-08-15 Thread Kent Johnson
[EMAIL PROTECTED] wrote: > Note that in Python2.4+, you can use key= instead: > > def sortKey(lst): > return lst[2] > Quant.sort(key=sortKey) > > This is more effient than specifying a different comparison function, because > the key function is only called once for each element. And instead of

Re: [Tutor] Sorting a list of lists aka nested lists

2005-08-14 Thread jfouhy
Quoting Alan G <[EMAIL PROTECTED]>: > > 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. > you need to wr

Re: [Tutor] Sorting a list of lists aka nested lists

2005-08-14 Thread Alan G
>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. you need to write your own comparison function. Basicall

Re: [Tutor] Sorting a list of lists aka nested lists

2005-08-13 Thread Danny Yoo
> >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 >

Re: [Tutor] Sorting a list of lists aka nested lists

2005-08-13 Thread Jim Roush
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(),

Re: [Tutor] Sorting a list of lists aka nested lists

2005-08-13 Thread Danny Yoo
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 sor