CODE: Generic Sort Routine
andrew.henshaw at gtri.gatech.edu
Mon Aug 23 13:27:42 CEST 2004
> I've written a generic sort routine that will sort dictionaries,
> lists, or tuples, either by a specified key or by value.
> Comments welcome!
> if key:
> sorted = zip([getattr(item, key) for item in thelist],
> sorted = list(thelist)
I'd change that 'if key:' line to 'if key is not None:', so that you could
sort on other non-True values.
More information about the Python-list