I have a file [ Name Age Marks] . I have stored each values of Name in a list1 . Marks in list2. I have combined both lists using zip function in python:
list3
sorted, list.sort accept optional key
function. Return values of the function are used for comparison.
>>> list3 = [('Steve',32),('David',65),('Ram',43),('Mary',87)]
>>> sorted(list3, key=lambda item: item[1])
[('Steve', 32), ('Ram', 43), ('David', 65), ('Mary', 87)]
>>> sorted(list3, key=lambda item: -item[1]) # negate the return value.
[('Mary', 87), ('David', 65), ('Ram', 43), ('Steve', 32)]
>>> sorted(list3, key=lambda item: item[1], reverse=True) # using `reverse`
[('Mary', 87), ('David', 65), ('Ram', 43), ('Steve', 32)]