Open this example in the interactive library
Source code
records = [('Ada', 2), ('Bob', 1), ('Grace', 2)]
print(sorted(records, key=lambda record: record[1]))Sample output
[('Bob', 1), ('Ada', 2), ('Grace', 2)]
Open this example in the interactive library
records = [('Ada', 2), ('Bob', 1), ('Grace', 2)]
print(sorted(records, key=lambda record: record[1]))[('Bob', 1), ('Ada', 2), ('Grace', 2)]