输入句子然后输入关键字输出显示关键字出现的次数这里有个例子:?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=" ")
展开