计算其中带有字母“ w”的单词,但仅(几乎完成)

时间:2019-03-27 20:51:15

标签: python

因此,目标是计算带有字母“ w”的句子中的单词数,我编写了代码以计算w的数量,但我无法获得它来计算单词总数。

items = ["whirring", "wow!", "calendar", "wry", "glass", "", "llama","tumultuous","owing"]
items = str(items)
acc_num = 0
for i in items:
    if i in ['w']:
        acc_num += 1
print(items)

1 个答案:

答案 0 :(得分:1)

只需检查字母w是否在单词中。

items = ["whirring", "wow!", "calendar", "wry", "glass", "", "llama","tumultuous","owing"]

count = 0
for i in items:
    if "w" in i:
        count +=1