# Python program to demonstrate sorting by user's Â
# choice Â
Â
# function to return the second element of the Â
# two elements passed as the parameter Â
def sortSecond(val): Â
  return val[1] Â
Â
# list1 to demonstrate the use of sorting Â
# using using second key Â
list1 = [(1, 2), (3, 3), (1, 1)] Â
Â
# sorts the array in ascending according to Â
# second element Â
list1.sort(key = sortSecond) Â
print(list1) Â
Â
# sorts the array in descending according to Â
# second element Â
list1.sort(key = sortSecond, reverse = True) Â
print(list1)