Jun-01-2019, 10:40 AM
So basically what I want is python code that counts how many times a word occurs in a paragraph for text auto summarization. I have managed to spit up the paragraph into sentences and sentences into words... So its a list of lists. And I am using the 'defaultdict" from the 'collections' library.
Here is my code:
I even tried like this:(Without using defaultdict)
Yet I am getting the same error:
Someone please help... Thank you!
P.S. This is my first post so please tell me if it is comprehensible or not.
Here is my code:
1 2 3 4 5 |
from collections import defaultdict freq = defaultdict( int ) for sentence in word_sent: #word_sent is my list of lists that I mentioned above. for word in sentence: freq[word] + = 1 |
1 2 3 4 5 6 7 |
freq = {} for sentence in word_sent: #word_sent is my list of lists that I mentioned above. for word in sentence: if word not in freq.keys(): freq[word] = 1 else : freq[word] + = 1 |
Error:RuntimeError: dictionary changed size during iteration
And this is the only dictionary I have in my entire code.Someone please help... Thank you!
P.S. This is my first post so please tell me if it is comprehensible or not.