小编Jak*_*est的帖子

为什么 sorted() 函数说传递 3 个参数时只需要一个参数?

我有一个简单的程序,它应该按键对数组进行排序。

为什么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

2
推荐指数
2
解决办法
76
查看次数

标签 统计

python ×1