Jun-01-2019, 11:08 AM
I am not getting the error that you did, you didn't give a sample of
You should give a proper sample of
word_sent
so i made my own.You should give a proper sample of
word_sent
so it can be tested in the same condition.from collections import defaultdict word_sent = [ ["word", "word2", "word3", "word"], ["word5", "word1", "word1", "word"], ["word5", "word2", "word2", "word"], ] 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 print(freq)
Output:defaultdict(<class 'int'>, {'word': 4, 'word2': 3, 'word3': 1, 'word5': 2, 'word1': 2})