If I have a the list
listOfFiles = [<str>,<intA>,<intB>]
How can I sort this list first by intA then by intB?
The end result would look like
<str>,1,1
<str>,1,2
<str>,1,3
<str>,2,1
<str>,2,2
etc
Use a compound key (or rather, a sequence as a key).
listOfFiles.sort(key=operator.itemgetter(1, 2))
operator.itemgetter.Python list sorting is done in place and is guaranteed to be stable after 2.4 (I believe, it may have been 2.5). That means you can sort like so and should get the results you want:
listOfFiles.sort(key = lambda x: x[2])
listOfFiles.sort(key = lambda x: x[1])
I presume you actually have a list of lists, or a list of tuples. If not, please provide a more complete example of your data structure.