【问题标题】:How can I compare each item of each list each other? etc. ['3','3', '1', '0.05'] ['5', '2', '4', '0.05'] if 3 equal to 5? [duplicate]如何相互比较每个列表的每个项目?等等 ['3','3', '1', '0.05'] ['5', '2', '4', '0.05'] 如果 3 等于 5? [复制]
【发布时间】:2020-10-01 12:40:53
【问题描述】:

This is currently what it is now

所以我想比较三角形 ['3', '3', '1', '0.05'] 的第一项是 3 然后拿它来比较下一个三角形的第一项 ['5 ', '2', '4', '0.05'] etc. if 3 == 5:我该怎么做

【问题讨论】:

  • 比较是什么意思?请更具体,并提供Minimal, Complete, and Verifiable example
  • 你应该在帖子中包含代码本身,而不是它的图片
  • 如果等于 5,则检查 3,如果等于第二个三角形的第一项,则为第一个三角形的第一项。

标签: python string list for-loop compare


【解决方案1】:
L1 = ['3','3', '1', '0.05'] 
L2 = ['5', '2', '4', '0.05']

L1 = [float(i) for i in L1]
L2 = [float(i) for i in L2]

for a,b in zip(L1, L2):
    if a==b:
        print(a, '=', b)
    else:
        print(a, '!=', b)

【讨论】:

    猜你喜欢
    • 2015-09-02
    • 2018-03-06
    • 1970-01-01
    • 2017-07-15
    • 1970-01-01
    • 1970-01-01
    • 2019-10-27
    • 1970-01-01
    • 2023-04-04
    相关资源
    最近更新 更多