我有一个脚本来查找列表中某个单词的计数
newm =[]
for i in range(0,len(alpha)-1):
newm.append (alpha[i][0])
print newm
#count for list
word_counter =[]
for word in newm:
print word
if word in word_counter:
word_counter[word] += 1
else:
word_counter[word] = 1
newm
生成:
['today', 'alpha', 'radiation', 'helium', 'work', 'charge', 'model', 'atom', 'discovery', 'interpretation', 'scattering', 'gold', 'foil', 'splitting', 'atom', 'reaction', 'nitrogen', 'alpha']
我想找到列表 newm 中每个单词的计数,但是它给出了错误:
TypeError: list indices must be integers, not str
我该如何解决?