#coding:utf-8
import operator
l = [(1, 5, 8), (6, 2, 4), (9, 7, 5)]
l.sort(key=operator.itemgetter(0)) #对该元组的第一个元素进行升序排列
print l
# [(1, 5, 8), (6, 2, 4), (9, 7, 5)]
l.sort(key=operator.itemgetter(2)) #对该元组的第三个元素进行升序排列
print l
# [(6, 2, 4), (9, 7, 5), (1, 5, 8)]
网友评论