Python Forum

Full Version: error
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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!
Remove this and it should work.
word = words
Thanks! That worked.