是否可以匹配两个元组,逐个比较每个元素,并确定更改发生在何处。
注意: runA和runB输出在循环中,这意味着它不是硬编码的。runA和runB可以是范围tool01到tool100或tool01等,这取决于对我的查询的循环结果。只是简单地说,工具在for循环中,所以工具no可以或多或少。
输出1的示例结果:
runA = [(u'tool01', '21'), (u'tool02', '22'), (u'tool03', '23')]
runB = [(u'tool01', '21'), (u'tool02', '22'), (u'tool03', '22')]预期结果1:
print 'there is a changes on tool03' 输出2的示例结果:
runA = [(u'tool01', '21'), (u'tool02', '22'), (u'tool03', '23')]
runB = [(u'tool01', '20'), (u'tool02', '21'), (u'tool03', '23')]预期结果2:
print 'there is a changes on tool01'
print 'there is a changes on tool02' 输出3的示例结果:
runA = [(u'tool01', '21'), (u'tool02', '22'), (u'tool03', '23')]
runB = [(u'tool01', '21'), (u'tool02', '22'), (u'tool03', '23')]预期结果3:
print 'there is no change'任何建议或基本代码,谢谢提前。
注意: runA和runB输出在循环中,这意味着它不是硬编码的。runA和runB可以是范围tool01到tool100或tool01等,这取决于对我的查询的循环结果。只是简单地说,工具在for循环中,所以工具no可以或多或少。
发布于 2015-10-23 01:49:28
runA = [(u'tool01', '21'), (u'tool02', '22'), (u'tool03', '23')]
runB = [(u'tool01', '21'), (u'tool02', '22'), (u'tool03', '22')]
for i in range(len(runA)):
if runA[i] == runB[i]:
print True
else:
print False发布于 2015-10-22 23:30:03
for i in runA - 1:
If runA[i][1] != runB[i][1]:
print 'there is a changes in ' + runA[i][0]假设有两件事:
正如您的一位评论者所建议的,使用dict会更容易,因为您可以遍历键并使用d[key]访问成员。
发布于 2015-10-22 23:38:45
#/bin/python
confirm_change=False
runA = [(u'tool01', '21'), (u'tool02', '22'), (u'tool03', '23')]
runB = [(u'tool01', '20'), (u'tool02', '21'), (u'tool03', '23')]
for i in runA:
for j in runB:
if i[0]==j[0] and not i[1]==j[1]:
confirm_change=True
print("there is a change in",i[0])
if confirm_change==False:
print("There is no change")https://stackoverflow.com/questions/33292438
复制相似问题