Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

python sort a list of tuples

my_list =[("p",23),("m",2),("q",19),("f",77),("a",50),]
# we will use the 'sort' method
my_list.sort(reverse = True, key = lambda t: t[1])
# the result will be
my_list
[('f', 77), ('a', 50), ('p', 23), ('q', 19), ('m', 2)]
 
PREVIOUS NEXT
Tagged: #python #sort #list #tuples
ADD COMMENT
Topic
Name
3+6 =