best Pythonic way to do this sort: Python newb
Brett Hoerner
bretthoerner at gmail.com
Mon Oct 10 01:28:53 EDT 2005
(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 order of the 'key' values, key being a value
returned from myFunction which operates on [2].
More information about the Python-list
mailing list