如何在 while 循环中使用 for 循环?这是我的代码:
def avoids(word,forbidden):
for fl in forbidden:
for letter in word:
if letter == fl:
return False
return True
fin= open('words.txt')
u=97
v=97
w=97
x=97
y=97
minim=100
while u <= 122:
while v <= 122:
while w <= 122:
while x <= 122:
while y <= 122:
count=0
for line in fin:
word = line.strip()
if avoids(word,chr(u)+chr(v)+chr(w)+chr(x)+chr(y)):
#print(word)
count+=1
#print((100/113809)*count)
if (100/113809)*count<minim:
print(count)
minim=(100/113809)*count
print(minim,chr(u)+chr(v)+chr(w)+chr(x)+chr(y))
y+=1
y=97
x+=1
x=97
w+=1
w=97
v+=1
v=97
u+=1
它只执行一次 for 循环。我可以将 fin= open('words.txt') 放在最新的 while 语句中,但随后程序变得非常缓慢且几乎无法使用。我能做什么?(不是我不想使用列表等)