I have the following function, the second function count_forbid(a)
can only work 1 time. In this example it count the right value of the word that do not contain letter 'c'
, but for y
it return zero. So it means the code can only do right first time and for all other time it return zero:
import string
fin = open('words.txt')
def forbid_or_not(word,forb):
for letter in word:
if letter in forb:
return False
return True
def count_forbid(a):
count = 0
for line in fin:
word1 = line.strip()
if forbid_or_not(word1,a):
count += 1
return count
x = count_forbid('c')
y = count_forbid('d')