# -*- encoding: utf-8 -*-
'''
author by Vicky 2019-04-20
'''
#打印下列句子中每个单词出现的次数:sentence='Hello hello how how are you'
sentence='hello hello how how are you'
sentence_list=sentence.split(' ')
word={}
for i in sentence_list:
word[i] = sentence_list.count(i)
print(sentence_list)
print(word)
本文介绍了一种简单的方法来统计给定字符串中每个单词的出现次数。通过将字符串转换为列表并使用字典来计数,可以有效地得到单词频率。
171万+

被折叠的 条评论
为什么被折叠?



