DEV Community

Discussion on: Build a quick Summarizer with Python and NLTK

Collapse
 
yingyangnc profile image
Praveen Christopher

any number i use gives the same error

sentenceValue[sentence[:2]] += wordValue[1]

IndexError: string index out of range

Thread Thread
 
davidisrawi profile image
David Israwi

Interesting. For debugging it, I would print all your sentences and find if there's an empty one (or a very short one), I think that may be the issue.

Let me know if that works or if you found the issue

Thread Thread
 
plabonislam profile image
plabonislam

i am also facing string index out of range problemm.,,what is the issue

Thread Thread
 
davidisrawi profile image
David Israwi

You may have a string that is less than your string length sentence[:2]. I would recommend printing the strings and see if this is the case

Thread Thread
 
plabonislam profile image
plabonislam • Edited

i have solved it..it was acctually puncutation problem..in my case...i just handle dot(.) character while giving words as value..

Thread Thread
 
ahmednagah103 profile image
Ahmed M.Nagah • Edited

Could you please help me , i'm facing same problem here and i can't handle it , tahnk you.

Thread Thread
 
davidisrawi profile image
David Israwi

Is this your error?

IndexError: string index out of range

If so, potential solutions could be:

  • Having a string that is less than your string length sentence[:2]. I would recommend printing the strings and see if this is the case.
  • Punctuation problem, like phabonislam explained above.

If that doesn't solve it, let me know!

Thread Thread
 
th0nker profile image
Run • Edited

It is still giving me an error when the text is > than 12 characters long and the sentance is (when printed through the loop) "You notice a wall of text in twitch chat and your hand instinctively goes to the mouse.", which is the first line in the paragraph. I found that even when you take out the range the same error occurs.

Thread Thread
 
davidisrawi profile image
David Israwi

The bug may be in how you are storing your sentences, make sure you print out the sentences as you store them instead of when you retrieve them, hopefully, that'll help you find the issue. If not, let me know if I can help!