def count_words(candidate_text, common_words=frequency.common_words['english'], case_sensitive=True):
'''
Count the instances of common words in the expected plaintext
language, return the total number of characters matched in each
word
candidate_text - (string) Sample to analyze
common_words - (list) Sequences expected to appear in the text
case_sensitive - (bool) Whether or not to match case sensitively
'''
score = 0
for word in common_words:
if not case_sensitive:
word = word.lower()
num_found = candidate_text.count(word)
if num_found > 0:
score += num_found * len(word)
return score
评论列表
文章目录