sorted expected 1 argument, got 2
时间: 2023-08-02 10:34:15 浏览: 75
这个错误提示通常表示你在使用 sorted() 函数时,传入了多余的参数。sorted() 函数只需要一个可迭代对象作为参数,用于排序。例如:
```
my_list = [3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5]
sorted_list = sorted(my_list)
print(sorted_list)
```
输出结果为:
```
[1, 1, 2, 3, 3, 4, 5, 5, 5, 6, 9]
```
请检查你的代码,看看是否有多余的参数传入 sorted() 函数中。如果问题仍然存在,请提供更多的代码和错误信息,以便我可以更好地帮助你解决问题。
相关问题
报错出现、sorted expected 1 argument, got 2怎么解决
这个错误提示说明你调用了 `sorted()` 函数时提供了多余的参数。在 Python 中,`sorted()` 函数需要传入一个可迭代对象作为参数,而可选的参数可以通过关键字参数的方式传递。如果你提供了多余的参数,Python 就会抛出这个错误。
要解决这个问题,你需要检查一下你的代码,看看是不是在调用 `sorted()` 函数时传入了多余的参数。如果是这样,你只需要删除多余的参数即可。另外,如果你确实需要传递关键字参数,可以使用 `**` 语法将它们打包成一个字典,然后将这个字典作为 `sorted()` 函数的最后一个参数传递。
相关推荐
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![txt](https://img-home.csdnimg.cn/images/20210720083642.png)
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)
![rp](https://img-home.csdnimg.cn/images/20210720083646.png)
![txt](https://img-home.csdnimg.cn/images/20210720083642.png)