You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
test_list= [['Rash', 4, 28], ['Varsha', 2, 20], ['Nikhil', 1, 20], ['Akshat', 3, 21]]
# printing original listprint ("The original list is : "+str(test_list))
# using sort() + lambda# to sort list of list# sort by second indextest_list.sort(key=lambdax: x[1])
sorted() + itemgetter()
fromoperatorimportitemgetter# initializing listtest_list= [['Rash', 4, 28], ['Varsha', 2, 20], ['Nikhil', 1, 20], ['Akshat', 3, 21]]
# printing original listprint ("The original list is : "+str(test_list))
# using sort() + lambda# to sort list of list# sort by second indexres=sorted(test_list, key=itemgetter(1))
# printing resultprint ("List after sorting by 2nd element of lists : "+str(res))