我有一个列表“distancechunks”,里面有 90 个列表。这 90 个列表中的每一个都由其中的 2 个元组组成(见图)。我想按第一个元组(图像中突出显示的黄色)对每个列表(总共 90 个)进行排序。因此,每个列表都是从低到高排序的。数组值(第 2 个元组)不应排序,只需在左侧保持相同的值。
我尝试了经典的东西,比如 .sort() 和用 lambda 等排序:
for x in distancechunks:
for i in x:
lst2 = sorted(i)
print(lst2)
但是,我总是收到不同的错误消息,例如:
ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()
或者我试过:
vallah = distancechunks
vallah.sort(key=lambda x: int(x[0]))
vallah
并得到错误信息:
int() argument must be a string, a bytes-like object or a number, not 'tuple'
不幸的是,我不确定如何实现这个错误......
这是“distancechunks”列表的摘录:
拉莫斯之舞
相关分类