将打开的文件中的两行与For循环进行比较



好吧,伙计们,这段代码能用,但不是我想要的。如果有人能帮我的话,我希望它在hash_replace中取第一行,检查hash_found中的每一行,直到找到一行,但这段代码只是并排比较它们。如果有人能帮忙,我将不胜感激。

with open('resolute','r') as renny:
with open('ronny','r') as renna:
for line,line2 in zip(renny,renna):
lin = line.split()
li = line2.split()
hash_to_replace = lin[2]
email = lin[0]
hash_found = li[0]
pass_found = li[2]
if hash_to_replace == hash_found:
print('Found')
else:
print('Nothing')

您需要2个嵌套循环:对于每个line,在所有line2上循环:

with open('resolute','r') as renny:
for line in renny:
with open('ronny','r') as renna:
for line2 in renna:

最新更新