Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Sort tuples

students = [
    ('John', 'A', 2),
    ('John', 'B', 2),
    ('John', 'A', 3),
    ('Anne', 'B', 1),
    ('Anne', 'A', 2),
    ('Anne', 'A', 1),
]
print(students)

print(sorted(students))

"""
[
    ('Anne', 'A', 1),
    ('Anne', 'A', 2),
    ('Anne', 'B', 1),
    ('John', 'A', 2),
    ('John', 'A', 3),
    ('John', 'B', 2)
]
"""