Python请问该如何修改

def sort_and_pop(x: list, i: int) -> list:
x.sort()
return x.pop(i)

我的代码
lst = [23, 17, 3, 13, 11, 5, 7, 2, 19, 1]
lst = sort_and_pop(lst, 5)
lst = sort_and_pop(lst, 2)

代码运行显示的错误
Traceback (most recent call last):
File "<pyshell#67>", line 1, in
lst = sort_and_pop(lst, 2)
File "/Users/stealthemoonwithme/Desktop/nbm.py", line 3, in sort_and_pop
x.sort()
AttributeError: 'int' object has no attribute 'sort'

请问该如何修改

第一次调用 pop返回数组项为数字,第二次在调用lst是数字,不是数组当然没有sort方法了,应该是return pop后的x参数

def sort_and_pop(x: list, i: int) -> list:
    x.sort()
    x.pop(i)
    return x

lst = [23, 17, 3, 13, 11, 5, 7, 2, 19, 1]
lst = sort_and_pop(lst, 5)
print(lst)
lst = sort_and_pop(lst, 2)
print(lst)

img

您好,我是有问必答小助手,您的问题已经有小伙伴帮您解答,感谢您对有问必答的支持与关注!
PS:问答VIP年卡 【限时加赠:IT技术图书免费领】,了解详情>>> https://vip.csdn.net/askvip?utm_source=1146287632