【发布时间】:2018-11-13 13:24:12
【问题描述】:
所以我有两个列表:
vocabulary = ['a','b','c']
sentences = ['a a b b c c', 'a c b c', 'b c c a b']
我想计算词汇表中的字母出现在列表句子的字符串中的次数。
所以我希望输出是:
a = 4
b = 5
c = 6
我的程序:
counter = Counter()
for word in sentences:
if word in vocabulary:
counter.update(word)
print(counter)
但我不断得到输出:
Counter()
【问题讨论】:
标签: python string python-3.x dictionary counter