0

テキスト ファイルに含まれる各単語の数をカウントする必要がある Python プログラムを作成しています。

def count_words(word,d):
    for l in word:
        if l in d:
            d[l] += 1
        else:
            d[l] = 1
        return d

def count_letters():
    d = dict()
    word_file = open('w.txt')
    for line in word_file:
        word = line.strip();
        d = count_words(word,d)
    return d
4

1 に答える 1