Spot the bug in the comparator

from functools
Python 3.14 intermediate 4 min 1 issue to find

Find why this comparator does not implement the contract required by cmp_to_key().

Python
from functools import cmp_to_key

def compare_priority(left, right):
    return left["priority"] < right["priority"]

tickets = [{"priority": 2}, {"priority": 1}]
print(sorted(tickets, key=cmp_to_key(compare_priority)))
Open in playground
Report an error