How can i use a for loop inside a while loop? Here is my code:
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
It executes the for loop for just one time. I can put fin= open('words.txt') inside the latest while statement but then program gets really slow & almost unusable. What can i do?(not that i don't want to use lists & etc.)
fin = open('words.txt')inside the last while loop because you are opening and reading the file11,881,376times... Are you sure that's how many loops you actually want??97and122should both be constants.