可能不是您想要的,但是通常您需要将After
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
另一种方法是使用生成器表达式将squash压缩
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 productfor word1, word2 in product(buf1, buf2): ... if res == res1: print "BINGO " + word1 + ":" + word2 break
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)