Dec-11-2018, 09:46 PM
(This post was last modified: Dec-11-2018, 09:53 PM by beepBoop123.)
Hi, I keep getting an error that says "str' object has no attribute 'items" on line 3 and I don't understand why. Can someone help me fix the code? Thanks!
def get_inverted_index(words): tweetDict = {} wordCount = {} for tweetKey, tweetText in words.items(): for word in tweetText.lower().split(): wordCount[word]=wordCount.get(word,0)+1 if inverted_index.get(word,False): if tweetKey not in tweetDict[word]: tweetDict[word].append(tweetKey) else: tweetDict[word] = [tweetKey] return tweetDict, wordCount
gettysburg_address = "Four score and.." print = (get_inverted_index(gettysburg_address))