Python3 下的sorted函数
>>> def reversed_cmp(x, y):
if x > y:
return -1
if x < y:
return 1
return 0
>>> sorted([36, 5, 12, 9, 21], cmp=reversed_cmp)
Traceback (most recent call last):
File "<pyshell#86>", line 1, in <module>
sorted([36, 5, 12, 9, 21], cmp=reversed_cmp)
TypeError: 'cmp' is an invalid keyword argument for this function
>>> sorted([36, 5, 12, 9, 21], reversed_cmp)
Traceback (most recent call last):
File "<pyshell#87>", line 1, in <module>
sorted([36, 5, 12, 9, 21], reversed_cmp)
TypeError: must use keyword argument for key function
>>> sorted([36, 5, 12, 9, 21], key=reversed_cmp)
Traceback (most recent call last):
File "<pyshell#88>", line 1, in <module>
sorted([36, 5, 12, 9, 21], key=reversed_cmp)
TypeError: reversed_cmp() missing 1 required positional argument: 'y'
Python3 下请问该怎么写?