I have code that takes in a text file and parses it to get the frequency of each word and store it in a dictionary.
# Load a corpus and build a language model
def load_model(filename):
"""Loads a corpus file and builds a language model consisting of word:frequency.
Converts all words to lowercase, strips punctuation, and ignores any non-alphabetic characters."""
dictionary = {}
f = open(filename)
for line in f:
words = line.split(' ') # Split each word and iterate through.
for string in words:
for c in string: # Check each character value for punctuation or numeric type.
if c in Punct:
string = string.replace(c,"")
if c.isdigit()
print String + ' is not formattable.\n'
break
string = string.lower()
if string in dictionary:
dictionary[string] = dictionary[string] + 1
else:
dictionary[string] = 1
f.close()
return dictionary
My question is I need break to end checking the entire string, not just to end checking a characters.
Does break end the loop it is located in or does it end the first loop: ("for line in f")
And, continue would simply end that particular loop.
I want it so that it ends checking the entire string and it moves on to the next string in words.