Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
error
#1
content = input('Enter English words:').lower()
counters = {}
words = content.split()

for word in words:
    
    word = words
    if word not in counters:
        counters [word] = 1 #First occurrence of a word starts counter
    else:
        counters [word] += 1 #if repeat word add to existing counter

for word, count in counters.items():
    print (word, count)
Error:
line 8, in <module> if word not in counters: builtins.TypeError: unhashable type: 'list'
I am trying to make a word count from words that a user enters and I came to this error and I am unfamiliar with it. If someone could explain or some good material that would help me better understand the error that would be great. Thanks!
Reply
#2
Remove this and it should work.
word = words
Reply
#3
Thanks! That worked.
Reply


Forum Jump:

User Panel Messages

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