a=[(1,"b"),(2,"a"),(1,"e")] print a print sorted(a) def myTSort(d): return d[0] # sort according to first value print sorted(a,key=myTSort) print sorted(a,key=myTSort, reverse=True) print a
Output:
[(1, 'b'), (2, 'a'), (1, 'e')] [(1, 'b'), (1, 'e'), (2, 'a')] [(1, 'b'), (1, 'e'), (2, 'a')] [(2, 'a'), (1, 'b'), (1, 'e')] [(1, 'b'), (2, 'a'), (1, 'e')]
0 comments:
Post a Comment