Python 統計一個英文單詞出現的頻率

統計單詞的個數

 def count(str):
     count_words = str.split()
    count_word = {}
    for word in count_words:
        if word not in count_word.keys():
            count_word[word] = 1
        else:
           count_word[word] += 1
    return count_word
 print(count('hello lily'))
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章