おそらくあなたが望んでいるものではありませんが、break
通常find
はTrue
for word1 in buf1:
find = False
for word2 in buf2:
...
if res == res1:
print "BINGO " + word1 + ":" + word2
find = True
break # <-- break here too
if find:
break
別の方法は、ジェネレータ式を使用しfor
てを単一のループに押しつぶすことです。
for word1, word2 in ((w1, w2) for w1 in buf1 for w2 in buf2):
...
if res == res1:
print "BINGO " + word1 + ":" + word2
break
使用を検討することもできますitertools.product
from itertools import product
for word1, word2 in product(buf1, buf2):
...
if res == res1:
print "BINGO " + word1 + ":" + word2
break