按两个字段对 Python 列表进行排序

问题描述:

我从排序的 csv 创建了以下列表

I have the following list created from a sorted csv

list1 = sorted(csv1, key=operator.itemgetter(1))

我实际上想按两个条件对列表进行排序:首先按字段 1 中的值,然后按字段 2 中的值.我该怎么做?

I would actually like to sort the list by two criteria: first by the value in field 1 and then by the value in field 2. How do I do this?

像这样:

import operator
list1 = sorted(csv1, key=operator.itemgetter(1, 2))