小编ARI*_*M K的帖子

在python中按元素比较两个列表

我有两个清单

first= (1,2,3,4,5,6)
last=(6,5,4,3,2,1)
Run Code Online (Sandbox Code Playgroud)

我只需要比较相应的值。我使用了下面的代码并获得了 36 个结果,因为第一个元素与最后一个列表的所有六个元素进行比较。

for x in first:
    for y in last:
        if x>y:
            print("first is greater then L2",y)
        elif x==y:
            print("equal")
        else:
            print("first is less then L2",y)

irst= (1,2,3,4,5,6)
last=(6,5,4,3,2,1)
for x in first:
    for y in last:
        if x>y:
            print("first is greater then L2",y)
        elif x==y:
            print("equal")
        else:
            print("first is less then L2",y)
Run Code Online (Sandbox Code Playgroud)

输出:

L1 is less then L2 6
L1 is less then L2 5
L1 is less then L2 4
L1 is less …
Run Code Online (Sandbox Code Playgroud)

python python-3.x

6
推荐指数
1
解决办法
2万
查看次数

标签 统计

python ×1

python-3.x ×1