Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/322.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
python检查列表1中的所有元素是否大于列表2中相同索引的元素_Python - Fatal编程技术网

python检查列表1中的所有元素是否大于列表2中相同索引的元素

python检查列表1中的所有元素是否大于列表2中相同索引的元素,python,Python,我有两份清单: x = [50,25,30] y = [25,30,50] 我是编程新手,如何用循环或其他函数确定x[0]>=y[0],x[1]>=x[1] 我想避免简单的: x[0] >= y[0] x[1] >= y[1] x[2] >= y[2] 因为这些列表可能会被附加 我分别将您的列表重命名为list1和list2: result = all(x >= y for x, y in zip(list1, list2)) 此处all(iterable)检查it

我有两份清单:

x = [50,25,30]
y = [25,30,50]
我是编程新手,如何用循环或其他函数确定x[0]>=y[0],x[1]>=x[1]

我想避免简单的:

x[0] >= y[0]
x[1] >= y[1]
x[2] >= y[2]

因为这些列表可能会被附加

我分别将您的列表重命名为
list1
list2

result = all(x >= y for x, y in zip(list1, list2))

此处
all(iterable)
检查
iterable
的所有元素是否为“truthy”

我分别将您的列表重命名为
list1
list2

result = all(x >= y for x, y in zip(list1, list2))

此处
all(iterable)
检查
iterable
的所有元素是否为“truthy”

我的解决方案将基于每个列表的长度相同这一事实

if len(x) == len(y):
    test_container = 0   #will store the number of trues
    for i in range(len(x)):
        if x[i] > y[i]:
            test_container += 1
    if test_container == len(x):
        print("All elements in x are bigger than the correspondent in y")
    else:
        print("False")

我的解决方案将基于每个列表的长度相同这一事实

if len(x) == len(y):
    test_container = 0   #will store the number of trues
    for i in range(len(x)):
        if x[i] > y[i]:
            test_container += 1
    if test_container == len(x):
        print("All elements in x are bigger than the correspondent in y")
    else:
        print("False")
result=True
为席,彝在邮编(X,Y):
如果席易:
结果=错误
打破
结果将包含答案

如果要将其作为一个函数来执行,请执行以下操作:

def compare(x, y):
    for xi, yi in zip(x, y):
        if xi < yi:
            return False
    return True
def比较(x,y):
为席,彝在邮编(X,Y):
如果席易:
返回错误
返回真值
结果=真
为席,彝在邮编(X,Y):
如果席易:
结果=错误
打破
结果将包含答案

如果要将其作为一个函数来执行,请执行以下操作:

def compare(x, y):
    for xi, yi in zip(x, y):
        if xi < yi:
            return False
    return True
def比较(x,y):
为席,彝在邮编(X,Y):
如果席易:
返回错误
返回真值