punctuation = ".,-{}[]()?!:" def next_word(f): for line in f: for w in line.split(): yield w.strip(punctuation)