Sorting a list of objects by multiple attributes

Scott David Daniels scott.daniels at acm.org
Tue Apr 11 11:57:26 EDT 2006


Kent Johnson wrote:
> In Python 2.5 you can do this with operator.attrgetter():
>   L.sort(key=operator.attrgetter('whatever', 'someother', 'anotherkey'))

Note: this is also available in Python 2.4

--Scott David Daniels
scott.daniels at acm.org



More information about the Python-list mailing list