Python error : 'tuple' object has no attribute 'upper'
Question: I wanna make word count and list how many times word counted. But

* * *
    
    
     f = open("Les.Miserable.txt", 'r')
    
     words = f.read().split()
     words.sort()
     wordCount = ()
    
     for i in range(len(words)):
         words[i] = words[i].replace(".", ""), (",", ""), ("/", ""), ("?", ""), ("!", "")
         words[i] = words[i].upper()
         if words[i] not in wordCount:
             wordCount[words[i]] = 1 
         else:
             wordCount[words[i]] += 1
    

i can see error message 'tuple' object has no attribute 'upper' in

    
    
    words[i] = words[i].upper()
    

here

and also error message 'tuple' object does not support item assignment in

wordCountint[words[i]] = 1

Please let me know know what is the problem


Answer: If you print the value of `words[i]` after your attempted character
replacements you will see that it is set to a `tuple`, e.g.

    
    
    ('word', (',', ''), ('/', ''), ('?', ''), ('!', ''))
    

So the line that tries to remove unwanted punctuation actually creates a tuple
because that's what the comma separated items are, i.e.

    
    
    words[i].replace(".", ""), (",", ""), ("/", ""), ("?", ""), ("!", "")
    

is actually a tuple consisting of `words[i].replace(".", "")` followed by
`(",", "")`, etc.

You might have meant to chain a whole lot of replace operations together, but
that would need to look like this:

    
    
    words[i].replace(".", "").replace(",", "").replace("/", "").replace("?", "").replace("!", "")
    

But that is pretty ugly, and it's restricted to just a few punctuation
symbols. `str.translate()` is better:

    
    
    words[i] = words[i].translate(None, '.,/?!')
    

or, if you want to get rid of all punctuation you can use
`string.punctuation`:

    
    
    import string
    words[i] = words[i].translate(None, string.punctuation)
    

Or, if you are using Python 3:

    
    
    import string
    words[i] = words[i].({ord(c):None for c in string.punctuation})
    

There are other problems in your code, but see if you can correct this first
issue first.

