How to sort a list of tuples by their first element?

后端 未结 3 863
情歌与酒
情歌与酒 2021-01-11 09:35

I have a list of tuples:

self.gridKeys = self.gridMap.keys() # The keys of the instance of the GridMap (It returns the product of every possible combination          


        
3条回答
  •  感情败类
    2021-01-11 09:59

    This should do the trick

    import operator
    self.gridKeys.sort(key=operator.itemgetter(1))
    

提交回复
热议问题