• Sort with itemgetter

 

Hi All,

I am working on doing a double sort and can't get the itemgetter to work. Any help would be appreciated. Also pointers to documentation would help as well. I'm finding it hard to locate anything that explains itemgetter.

When I run the itemgetter line, I am getting an error "IndexError: list index out of range". But if I run it as (0) or (1) it works just fine.

def manextsort(files:list)->list:

import operator

newlist = []

for x in files:

    # I get a 2D list by using .rsplit(".",1)

    newlist.append(x.rsplit(".",1))

lastlist = sorted(newlist, key=operator.itemgetter(0,1))