What arguments does Python sort() function have?

前端 未结 3 1860
深忆病人
深忆病人 2020-12-03 01:47

Is there any other argument than key, for example: value?

3条回答
  •  醉梦人生
    2020-12-03 02:23

    Besides key=, the sort method of lists in Python 2.x could alternatively take a cmp= argument (not a good idea, it's been removed in Python 3); with either or none of these two, you can always pass reverse=True to have the sort go downwards (instead of upwards as is the default, and which you can also request explicitly with reverse=False if you're really keen to do that for some reason). I have no idea what that value argument you're mentioning is supposed to do.

提交回复
热议问题