Use key instead of cmp for sorting in Python 3