示例#1
0
def count_words_in_file(file_name):
    word_statistics = defaultdict(int)
    all_words = get_words_from_file(file_name)

    # This is our main loop for counting words
    for word in all_words:
        word_statistics[word] += 1

    return word_statistics
示例#2
0
def count_words_in_file(file_name):
    word_statistics = {}
    all_words = get_words_from_file(file_name)

    # This is our main loop for counting words
    for word in all_words:
        try:
            word_count = word_statistics[word]
        except KeyError:
            word_count = 0

        word_count += 1
        word_statistics[word] = word_count

    return word_statistics
示例#3
0
def count_words_in_file(file_name):
    all_words = get_words_from_file(file_name)
    word_statistics = Counter(all_words)

    return word_statistics