欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

Python 统计一个英文单词出现的频率

程序员文章站 2024-02-23 23:30:28
...

统计单词的个数

 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'))