且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

按功能对列表进行排序会导致错误的结果

更新时间:2023-11-23 16:34:40

因为函数的参数指定为* a,这就像说您的参数是未定义维的元组

because the argument of your function is specified as *a, which is like saying your argument is a tuple of undefined dimension

当您尝试对带有嵌套列表的元组进行排序时,该值不会更改

when you try to sort a tuple with a nested list, the value will not change

事实上,您获得了列表列表(您获得了[[3,2,1]]而不是[3,2,1])

infact as result you got a list of list (you got [[3, 2, 1]] not [3, 2, 1])

如果您尝试这样做,它将起作用

if you try this, it will work

def foo(*x): 
    y=sorted(x[0]) 
    print(y)