Sorting a list of objects by multiple attributes
Scott David Daniels
scott.daniels at acm.org
Tue Apr 11 17:05:21 EDT 2006
Kent Johnson wrote:
> Scott David Daniels wrote:
>> 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
>
> No, the ability to specify more than one attribute name, making a getter
> that returns a tuple, is a Python 2.5 enhancement.
Yup, sorry about that. When I installed 2.5a1 the shortcuts I used for
2.4 got switched w/o my noticing (I did try it first). I have now made
my 2.4 shortcuts more explicit (so the next time I'll do this stupid
thing is likely on 2.6).
--
-Scott David Daniels
scott.daniels at acm.org
More information about the Python-list
mailing list