I have a script to find the count of some word in a list
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 generates:
['today', 'alpha', 'radiation', 'helium', 'work', 'charge', 'model', 'atom', 'discovery', 'interpretation', 'scattering', 'gold', 'foil', 'splitting', 'atom', 'reaction', 'nitrogen', 'alpha']
I want to find the count of each word in the list newm however it gives the error:
TypeError: list indices must be integers, not str
How can i fix it?
newmcan be defined as :newm = [item[0] for item in alpha]