python爬新闻并统计每个词出现的次数_python 可以统计出 一个词的出现的次数的代码...

输入句子然后输入关键字输出显示关键字出现的次数这里有个例子:?ihaveacarandabighouse?iamateacher?iloveyoutoomuch?thatweshouddothis?stopEnteryoursearchword:andandoccurs1tim...

输入句子

然后输入 关键字

输出 显示 关键字 出现的次数

这里有个例子:

? i have a car and a big house

? i am a teacher

? i love you too much

? that we shoud do this

? stop

Enter your search word: and

and occurs 1 times.

Enter your search word : i

i occurs 3 times.

Enter your search word stop ( 当输入stop 这个代码将结束)

如何实现这个功能请大侠解答!!!!!万分感激!

目前代码我只写到了 wordList

但不知道如何从 wordList 中搜索出 searchWord 的 数量!

sentence='holder'

wordList=[]

while sentence!='stop':

sentence=input("?")

wordList.append(sentence)

if sentence=='stop':

sentence=sentence.lower()

wordList.remove("stop")

wordCount=0

result=0

while searchWord!='stop':

searchWord=input("Enter your search word")

words=wordList[wordCount] (从这里开始真不知道该如何写了)

words_split=words.split(sep=" ")

展开

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值