Fix sorting for Python 3