我需要检查一个元组列表是否按照元组的第一个属性排序。最初,我想将该列表与其已排序的副本进行比较,例如...
list1 = [(1, 2), (4, 6), (3, 10)]
sortedlist1 = sorted(list1, reverse=True)
我如何检查list1是否与sortedlist1相同?这里的相同指的是
list1[0] == sortedlist1[0], and list1[1] == sortedlist1[1]
。由于我不确定列表的长度可能是5或100,因此执行
list1[0] == sortedlist1[0], and list1[1] == sortedlist1[1]
并不是一个好选择。谢谢。
False
,后者返回True
)。 - Pierce Darragh