Re: [Tutor] Sorting a list of objects on different fields

2006-03-02 Thread Terry Carroll
On Thu, 2 Mar 2006, Terry Carroll wrote: > Thanks, Kent! I didn't know about "key=". I see it's new in 2.4. > I was thinking I'd have to put in a method for each potentially sortable > field. And, in the spirit of RTFM, I should have been looking here first: http://wiki.python.org/moin/How

Re: [Tutor] Sorting a list of objects on different fields

2006-03-02 Thread Terry Carroll
On Thu, 2 Mar 2006, Kent Johnson wrote: > In [9]: lst.sort(key=attrgetter('b')); print lst Thanks, Kent! I didn't know about "key=". I see it's new in 2.4. I was thinking I'd have to put in a method for each potentially sortable field. ___ Tutor ma

Re: [Tutor] Sorting a list of objects on different fields

2006-03-02 Thread Kent Johnson
Terry Carroll wrote: > I have a list (or a list-like object, doesn't matter) of objects, each of > which has multiple fields. I want to be able to arbitrarily sort the list > on any of them, or at least on several of them. > > To make this a little more concrete, here's a simplified idea. Say th

[Tutor] Sorting a list of objects on different fields

2006-03-02 Thread Terry Carroll
I have a list (or a list-like object, doesn't matter) of objects, each of which has multiple fields. I want to be able to arbitrarily sort the list on any of them, or at least on several of them. To make this a little more concrete, here's a simplified idea. Say the objects each represent a fil