Re: sort help

2015-09-23 Thread Larry Martell
On Tue, Sep 22, 2015 at 6:55 PM, Chris Angelico wrote: > On Wed, Sep 23, 2015 at 8:42 AM, Larry Martell > wrote: >> I currently have 3 lists of lists and I sort them based on a common >> field into a single list like this: >> >> def GetObjKey(a): >> return a[2] >> >>

Re: sort help

2015-09-23 Thread Peter Otten
Larry Martell wrote: > I currently have 3 lists of lists and I sort them based on a common > field into a single list like this: > > def GetObjKey(a): > return a[2] > > sorted(a + b + c, key=GetObjKey) > > Which works just fine. > > But now, I need to have just the

Re: sort help

2015-09-22 Thread Paul Rubin
Larry Martell writes: > def GetObjKey(a): > return a[2] This function is called operator.itemgetter: from operator import itemgetter sorted(a + b + c, key=itemgetter(2)) > So for example, if my initial data was this (I'll only show the fields > involved with the sort

Re: sort help

2015-09-22 Thread Chris Angelico
On Wed, Sep 23, 2015 at 9:02 AM, Ian Kelly wrote: > On Tue, Sep 22, 2015 at 4:55 PM, Chris Angelico wrote: >> The Python list.sort() method is guaranteed to be >> stable. I can't find a comparable guarantee for sorted() > > https://docs.python.org/3.5/library/functions.html#sorted Right, sorry.

Re: sort help

2015-09-22 Thread Ian Kelly
On Tue, Sep 22, 2015 at 4:55 PM, Chris Angelico wrote: > The Python list.sort() method is guaranteed to be > stable. I can't find a comparable guarantee for sorted() https://docs.python.org/3.5/library/functions.html#sorted -- https://mail.python.org/mailman/listinfo/python-list

Re: sort help

2015-09-22 Thread Chris Angelico
On Wed, Sep 23, 2015 at 8:42 AM, Larry Martell wrote: > I currently have 3 lists of lists and I sort them based on a common > field into a single list like this: > > def GetObjKey(a): > return a[2] > > sorted(a + b + c, key=GetObjKey) > > Which works just fine. > > But

sort help

2015-09-22 Thread Larry Martell
I currently have 3 lists of lists and I sort them based on a common field into a single list like this: def GetObjKey(a): return a[2] sorted(a + b + c, key=GetObjKey) Which works just fine. But now, I need to have just the first list (a) also sub sorted by another fi