如果每个字符串中的索引匹配,我如何通过索引 return 布尔值比较两个 python 列表?
How can I compare two python lists by index return a Boolean if the index in each string matches?
a = [1, 2, 3, 4, 5]
b = [9, 8, 7, 6, 5]
期望的输出
False
False
False
False
True
a = [1, 2, 3, 4, 5]
b = [9, 8, 7, 6, 5]
for first, second in zip(a, b):
print(first == second)
请记住,这是假设 a
和 b
的长度相同。否则它只会迭代两个列表中较短的一个。
a = [1, 2, 3, 4, 5]
b = [9, 8, 7, 6, 5]
期望的输出
False
False
False
False
True
a = [1, 2, 3, 4, 5]
b = [9, 8, 7, 6, 5]
for first, second in zip(a, b):
print(first == second)
请记住,这是假设 a
和 b
的长度相同。否则它只会迭代两个列表中较短的一个。