Sorting a Python list by two fields

前端 未结 7 1119
不思量自难忘°
不思量自难忘° 2020-11-22 07:51

I have the following list created from a sorted csv

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

I would actually like to sort the list

7条回答
  •  野性不改
    2020-11-22 08:30

    like this:

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

提交回复
热议问题