I want a case-insensitive sort of a tuple of records (lists) on two fields in each record. HowTo/Sorting tells me how to do case-insensitive (key=str.lower
), and it tells me how to sort on two keys (key=operator.itemgetter(0,1)
). I tried the following:
parts = [
('A',2,''),
('a',1,''),
('b',2,''),
('B',1,''),
]
foo = sorted(parts, key=str.lower, key=operator.itemgetter(0,1))
print(foo)
Python does not like two key=
s in the same sorted
. It says: SyntaxError: keyword argument repeated
, pointing to the second instance of key=
.
How can I get a case-insensitive sort, and sort on multiple fields, too?