【发布时间】:2019-03-25 03:19:38
【问题描述】:
我在这里要做的是比较成对的整数。
如果我有配对列表
[(10, 5), (6, 3), (2, 20), (100, 80)]
我想比较每对的 x > y 如果任何对不满足条件,则返回 False
def function(list_or_tuple):
num_integers = len(list_or_tuple)
pairs_1 = list(zip(list_or_tuple[::2], list_or_tuple[1::2]))
print(pairs_1)
#pairs_2 = list(zip(list_or_tuple[1::2], list_or_tuple[2::2]))
#print(pairs_2)
for x1, y1 in pairs_1:
return bool(x1 > y1)
对于上面的例子,我的程序继续返回 True
我相信程序只测试第一对,即 (10,5)
我应该怎么做才能让我的程序测试列表中的所有对?
【问题讨论】:
标签: python python-3.x list for-loop