How does a Python custom comparator work?

前端 未结 4 1505
甜味超标
甜味超标 2021-01-06 19:52

I have the following Python dict:

[(2, [3, 4, 5]), (3, [1, 0, 0, 0, 1]), (4, [-1]), (10, [1, 2, 3])]

Now I want to sort them on the basis o

4条回答
  •  一向
    一向 (楼主)
    2021-01-06 20:45

    Basically, for the simple list such as [2, 4, 6, 3, 1] and the complex list you provided, the sorting algorithms are the same.

    The only differences are the complexity of elements in the list and the comparing scheme that how to compare any tow elements (e.g. myComparator you provided).

    There is a good description for Python Sorting: https://wiki.python.org/moin/HowTo/Sorting

提交回复
热议问题