Answers for "how to sort using lambda in python"

5

how to sort a list in python using lambda

data = [("Apples", 5, "20"), ("Pears", 1, "5"), ("Oranges", 6, "10")]

data.sort(key=lambda x:x[0])
print(data)
OUTPUT
[('Apples', 5, '20'), ('Oranges', 6, '10'), ('Pears', 1, '5')]

from kite.com
^^
Posted by: Guest on November-07-2020
4

sorted python lambda

lst = [('candy','30','100'), ('apple','10','200'), ('baby','20','300')]
lst.sort(key=lambda x:x[1])
print(lst)
Posted by: Guest on June-23-2020
2

python sort based off lambda

a = sorted(a, key=lambda x: x.modified, reverse=True)
Posted by: Guest on March-22-2021

Code answers related to "how to sort using lambda in python"

Python Answers by Framework

Browse Popular Code Answers by Language