Sorting Lists

Chris Barker chrishbarker at home.net
Wed Jul 25 14:36:19 EDT 2001


Nick Perkins wrote:

> You don't have to use a custom compare sort.
> You can get what you want by creating a temp list, consisting of 'decorated'
> values, and sorting that list.  These are actually tuples whose second
> element is the real data, and the first element is a copy of the field that
> you want to sort by.  (or a computed value, if you want)

Note that this will only work if all the items in your list are
sortable, not just the one you actually want to sort by, which is often,
but not always, the case.

Building your own compare function can get around this.

-Chris


-- 
Christopher Barker,
Ph.D.                                                           
ChrisHBarker at home.net                 ---           ---           ---
http://members.home.net/barkerlohmann ---@@       -----@@       -----@@
                                   ------@@@     ------@@@     ------@@@
Oil Spill Modeling                ------   @    ------   @   ------   @
Water Resources Engineering       -------      ---------     --------    
Coastal and Fluvial Hydrodynamics --------------------------------------
------------------------------------------------------------------------



More information about the Python-list mailing list