Replace deprecated cmp parameter in sorted() calls with key=cmp_to_key() to fix Python 3 compatibility. The cmp parameter was removed in Python 3.0.
- Use functools.cmp_to_key() as the official migration path
- Maintains identical sorting behavior across Python versions
- Fixes: TypeError: ‘cmp’ is an invalid keyword argument for sorted()