How does Python sort a list of tuples?

后端 未结 5 1709
广开言路
广开言路 2020-12-08 18:33

Empirically, it seems that Python\'s default list sorter, when passed a list of tuples, will sort by the first element in each tuple. Is that correct? If not, what\'s the ri

5条回答
  •  轮回少年
    2020-12-08 18:53

    Yes, this is the default. In fact, this is the basis of the classic "DSU" (Decorate-Sort-Undecorate) idiom in Python. See Code Like a Pythonista.

提交回复
热议问题