因此,目标是计算带有字母“ 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)
答案 0 :(得分:1)
只需检查字母w是否在单词中。
items = ["whirring", "wow!", "calendar", "wry", "glass", "", "llama","tumultuous","owing"]
count = 0
for i in items:
if "w" in i:
count +=1