我有一个简单的程序,它应该按键对数组进行排序。
为什么sorted()函数说它只需要 1 个参数,而我没有提供任何参数?
import operator
array = [[1, 6, 3], [4, 5, 6]]
sorted_array = sorted(iterable=array, key=operator.itemgetter(array[0][1]), reverse=True)
print(sorted_array)
Run Code Online (Sandbox Code Playgroud)
这给出了错误:
import operator
array = [[1, 6, 3], [4, 5, 6]]
sorted_array = sorted(iterable=array, key=operator.itemgetter(array[0][1]), reverse=True)
print(sorted_array)
Run Code Online (Sandbox Code Playgroud) python ×1