Python 3.x : using a list, if a letter isn't in that list, add it. otherwise, increment the value by 1
<p>so this is what I'm doing: I'm pulling up a file and having the program read it. Every time it encounters a letter, it'll add the letter to list1 and add '1' to list2. Every time it encounters a letter in list1, it'll increment list2 by 1. </p>

<pre><code>txt = open("Nameoffile.txt")
wordcount = 0
Charcount = 0
letterlist = [] #list 1
lettercount = [] #list 2

for words in txt:
    print(words)
    for letters in words:
        if letters not in letterlist:
           letterlist.append(letters)
           lettercount[letters] = 1
        else:
           lettercount[letters] += 1

        Charcount += 1
        print(letters)
        if letters == ' ':
           wordcount += 1
        if letters == '.':
           wordcount += 1
        if letters == '\n':
           Charcount -= 1
           wordcount += 1

#down here it would print the results
</code></pre>

<p>the problem I'm running into is that when running this, I get the following error:
line 14, lettercount[letters] = 1
TypeError: list indices must be integers or slices, not str</p>

<p>I assumed I could get away with stating that at list[letter] set that value to a number, but it isn't liking it. any possible hints on what to do?</p>

<p>lettercount should be type dict, not list. 
Type dict maps a unique key to a value, while list just contains values.
The value within brackets for a list should be an integer referring to a position in the list, while a dictionary will reference the key in brackets. </p>

python list python-3.x append increment