Python finding index in a array
Posted
by
NIH
on Stack Overflow
See other posts from Stack Overflow
or by NIH
Published on 2012-11-23T04:56:45Z
Indexed on
2012/11/23
4:59 UTC
Read the original article
Hit count: 109
python
I am trying to see if a company from a list of companies is in a line in a file. If it is I utilize the index of that company to increment a variable in another array. The following is my python code. I keep getting the following error: AttributeError: 'set' object has no attribute 'index'. I cannot figure out what is going wrong and think the error is the line that is surrounded by **.
companies={'white house black market', 'macy','nordstrom','filene','walmart'}
positives=[0 for x in xrange(len(companies))]
negatives=[0 for x in xrange(len(companies))]
for line in f:
for company in companies:
if company in line.lower():
words=tokenize.word_tokenize(line)
bag=bag_of_words(words)
classif=classifier.classify(bag)
if classif=='pos':
**indice =companies.index(company)**
positives[indice]+=1
elif classif=='neg':
**indice =companies.index(company)**
negatives[indice]+=1
© Stack Overflow or respective owner