How do I sort tuples in Python with type hints?

Sorting, Tuples, Python, Type Hints
This article explains how to sort tuples in Python using type hints for better code clarity and type checking.

from typing import List, Tuple

def sort_tuples(tuples: List[Tuple[int, str]]) -> List[Tuple[int, str]]:
    return sorted(tuples, key=lambda x: x[0])

# Example usage:
data = [(3, "banana"), (1, "apple"), (2, "cherry")]
sorted_data = sort_tuples(data)
print(sorted_data)  # Output: [(1, 'apple'), (2, 'cherry'), (3, 'banana')]
    

Sorting Tuples Python Type Hints