Python: Sort a list of lists by a given index of the inner list using lambda
37. Sort List by Index Lambda
Write a Python program to sort a list of lists by a given index of the inner list using lambda.
Sample Solution:
Python Code :
Sample Output:
Original list: [('Greyson Fulton', 98, 99), ('Brady Kent', 97, 96), ('Wyatt Knott', 91, 94), ('Beau Turnbull', 94, 98)] Sort the said list of lists by a given index ( Index = 0 ) of the inner list [('Beau Turnbull', 94, 98), ('Brady Kent', 97, 96), ('Greyson Fulton', 98, 99), ('Wyatt Knott', 91, 94)] Sort the said list of lists by a given index ( Index = 2 ) of the inner list [('Wyatt Knott', 91, 94), ('Brady Kent', 97, 96), ('Beau Turnbull', 94, 98), ('Greyson Fulton', 98, 99)]
For more Practice: Solve these Related Problems:
- Write a Python program to sort a list of lists by the element at a specified index in each inner list using lambda.
- Write a Python program to sort a list of lists by the sum of the elements in the inner list using lambda.
- Write a Python program to sort a list of lists by the difference between two specified indices using lambda.
- Write a Python program to sort a list of lists by the maximum element in each inner list using lambda.
Go to:
Previous: Write a Python program to extract the nth element from a given list of tuples using lambda.
Next: Write a Python program to remove all elements from a given list present in another list using lambda.
Python Code Editor:
Have another way to solve this solution? Contribute your code (and comments) through Disqus.
What is the difficulty level of this exercise?
Test your Programming skills with w3resource's quiz.