Re: best Pythonic way to do this sort: Python newb

2005-10-10 Thread George Sakkis
"Satchidanand Haridas" <[EMAIL PROTECTED]> wrote: > >So, I want to sort myList by the return of myFunction( value3 ) > > > >I tried doing the following... with no luck so far > >myList.sort(lambda x, y: cmp(myFunction(x[2]), myFunction(y[2])) > > > > > > > I think the above statement should be as

Re: best Pythonic way to do this sort: Python newb

2005-10-09 Thread Brett Hoerner
(sorted is a built-in function in 2.4) def myFunction( data ): """ Take one of your set of 3, grab [2] (the 3rd) and do calcs, return value """ "do some math calculations to data[2]" return "result of calculations" sorted_list = sorted(myList, key=myFunction) List is sorted in the or

Re: best Pythonic way to do this sort: Python newb

2005-10-09 Thread Paul Rubin
"Sean Berry" <[EMAIL PROTECTED]> writes: > > def get_key(x): return x[2] > > sorted_list = sorted(myList, key=get_key) > > Sorry if I am missing something. But. what is sorted here? sorted is a built-in function that sorts the thing that you pass it. It just appeared in Python 2.4, I think. Wit

Re: best Pythonic way to do this sort: Python newb

2005-10-09 Thread Satchidanand Haridas
Satchidanand Haridas (sharidas at zeomega dot com) ZeOmega (www.zeomega.com) Open Minds' Open Solutions Sean Berry wrote: >"Paul Rubin" wrote in message >news:[EMAIL PROTECTED] > > >>"Sean Berry" <[EMAIL PROTECTED]> writes: >> >> >>>myList = [[value1, v

Re: best Pythonic way to do this sort: Python newb

2005-10-09 Thread Sean Berry
"Paul Rubin" wrote in message news:[EMAIL PROTECTED] > "Sean Berry" <[EMAIL PROTECTED]> writes: >> myList = [[value1, value2, value3],[value1, value2, value3], ...] >> >> I have a function which takes value3 from the lists above and returns >> another value. I want to

Re: best Pythonic way to do this sort: Python newb

2005-10-09 Thread Paul Rubin
"Sean Berry" <[EMAIL PROTECTED]> writes: > myList = [[value1, value2, value3],[value1, value2, value3], ...] > > I have a function which takes value3 from the lists above and returns > another value. I want to use this returned value to sort the lists. > > So, my resultant list would be ordered