I am getting this problem . my python code is

 for i,j in nltk.pos_tag(words):
        print i,j
        if 'JJ' in j:
            pj=(list(swn.senti_synsets(i,'a'))[0]).pos_score()
            print "pj:" ,pj
        elif 'RB' in j:
            pr =(list(swn.senti_synsets(i,'r'))[0]).pos_score()
            print "pr:" ,pr
        elif 'NN' in j:
            pn =(list(swn.senti_synsets(i,'n'))[0]).pos_score()
            print "pn:" ,pn
        elif 'VB' in j:
            pv =(list(swn.senti_synsets(i,'v'))[0]).pos_score()
            print "pv:" ,pv

where "words" is a list of words containing adjective , adverb , noun etc..
words=['good','only','excellent','really'.........] nearly 300 such words. when i run this code it works for first 2 words .that is positive score of good and only will b displayed. but when it goes to word "excellent " there is this error..
output:
good JJ
pj: 0.75
only RB
pr: 0.0
excellent JJ

    Traceback (most recent call last):
      File "C:\Python27\mat to file.py", line 39, in <module>
        pj+=(swn.senti_synsets(i,'a')[0]).pos_score()
    IndexError: list index out of range

please help !!!!

The list list(swn.senti_synsets(i,'a')) is probably the empty list [ ] You could check this by printing its repr() for example. Your program does not (yet) handle the case where this list is empty. You must add some code.

commented: thanku..it was tagged wrongly +0

Also the example code and the example error message you gave us are different, the error message has pj+=(swn.senti_synsets(i,'a')[0]).pos_score() and the example code has pj=(list(swn.senti_synsets(i,'a'))[0]).pos_score(). Not sure what you're trying to accomplish with this code, but I'm pretty sure you get your error from code that wasn't shown in the example.

commented: code has pj+=(list(swn.senti_synsets(i,'a')[0]).pos_score() . i forgot to include. thankyou. +0
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.