写一个循环来计算单词表中单词在lis中出现的次数

2024-10-02 02:34:41 发布

您现在位置:Python中文网/ 问答频道 /正文

count = 0
for word in newWordList:
    newWordList= word.count('theBells')
    count += 1
print(newWordList)

Tags: inforcountwordprintnewwordlistthebells
1条回答
网友
1楼 · 发布于 2024-10-02 02:34:41

根据我对标题中问题的理解,没有太多细节,这是一种方法。wordList是要查找的源列表,inList是输入。在

count = 0
wordList=["hello","hi","is","and", "are", "you"]

#'are' appears twice and 'you' once - total should be 3
inList=["how", "are","you", "where", "are", "your", "friends" ]
count = 0
#count number of times the words in wordList appear in the input list 'inList'
for word in inList:
    if word in wordList:
        count += 1
print(count)

输出:

^{pr2}$

相关问题 更多 >

    热门问题