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]
>>
>>
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
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
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.
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
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
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