xxxxxxxxxx
a = sorted(a, key=lambda x: x.modified, reverse=True)
xxxxxxxxxx
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
^^
xxxxxxxxxx
a = ["tim", "bob", "anna", "steve", "john"]
# sorts the list by the first letter of each name
b = sorted(a, key=lambda x : x[0])
# x = each of the values in the list a
# sorts the list by length FIRST, then alphabetical order SECOND
c = sorted(a, key=lambda x : (len(x), x))
xxxxxxxxxx
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')]
xxxxxxxxxx
lst = ['id01', 'id10', 'id02', 'id12', 'id03', 'id13']
lst_sorted = sorted(lst, key=lambda x: int(x[2:]))
print(lst_sorted)