Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Dictionary Homework
#1
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))
Reply


Messages In This Thread
Dictionary Homework - by beepBoop123 - Dec-11-2018, 09:46 PM
RE: Dictionary Homework - by buran - Dec-11-2018, 09:52 PM
RE: Dictionary Homework - by ichabod801 - Dec-11-2018, 09:52 PM
RE: Dictionary Homework - by buran - Dec-11-2018, 10:00 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Dictionary/List Homework ImLearningPython 22 10,807 Dec-17-2018, 12:12 AM
Last Post: ImLearningPython

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020