# Python Dictionary holding wrong values

I am creating a hangman algorithm in Python as a learning project, I have a list of words the computer picks at random and filters etc. It has 8 lives to guess the word.

I have a dictionary in python called `a_count` - which stores the frequency of each letter in a specific list. The plan was to start off with a list of 12500 words, calculate the max frequency (`nGuess`) and then filter the list based on whether it does or does not contain that word. It then removes the letter `nGuess` from `a_count` so it doesn't try to pick the same letter again.

My issue is my list of words `nlist` is being filtered correctly (down to 125 in the final iteration) and the length of `a_count` appears to be removing letters accordingly (down to 17 in the last iteration however, `a_count` appears to be holding on to values from maybe the first time I initialized values to it.

`{'H': 1682, 'D': 2364, 'G': 1576, 'B': 1547, 'C': 1947, 'K': 1426, 'F': 1071, 'M': 1908, 'P': 1945, 'Y': 1992, 'W': 1013, 'V': 661, 'Z': 412, 'X': 268, 'J': 270, 'Q': 104}`

My list of words is 125 at this point so the sum of values should equal 625 (5*125)

The code is as below:

``````while life > -1 and pos < 5:
if life == 0:
loses = loses + 1
break

nword = []
word = []
letters = []
chars = []

for word in nlist:
nword.append(word)
for letters in chars:
a_count[letters] = a_count.get(letters, 0) + 1

for x in blacklist:
a_count.pop(x, 0)

for x in whitelist:
a_count.pop(x, 0)

print(a_count)
print(len(nlist))
nGuess = (max(a_count.items(), key=operator.itemgetter(1)))

print(nword)
print(str(nGuess) + ' is my next guess')

nlist = []
flist = []
hlist = []

for g in nword:
if nGuess in g:
flist.append(g)

for g in nword:
if nGuess not in g:
hlist.append(g)

if nGuess in tokens:
nlist = flist
whitelist.append(nGuess)
print(str(nGuess) + ' is in the word')
pos = tokens.count(nGuess) + pos
else:
nlist = hlist
blacklist.append(nGuess)
life = life - 1
print(str(nGuess) + ' is not in the word, I have ' + str(life) + ' lives left')

if pos == 5:
wins = wins + 1
break
``````

Can anyone see what the issue is? Am I right in saying after the first iteration (not shown in the code) is that storing the values in the dictionary, and then subsequent `a_count` is adding to the current list? As the pop is working, I'm just not getting the count's I would expect.

Even when I was left with a list of 4 words it was choosing a letter than wasn't even in any of those words! So the issue definitely lies with `a_count`
{"ft_lang_label":"__label__en","ft_lang_prob":0.8796317,"math_prob":0.8495241,"size":2761,"snap":"2021-21-2021-25","text_gpt3_token_len":790,"char_repetition_ratio":0.11751904,"word_repetition_ratio":0.00814664,"special_character_ratio":0.3103948,"punctuation_ratio":0.14188035,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.96322376,"pos_list":[0],"im_url_duplicate_count":[null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2021-05-11T04:57:14Z\",\"WARC-Record-ID\":\"<urn:uuid:65a6cb1a-5df3-40f3-b2bd-4ce9d9ab4c28>\",\"Content-Length\":\"57932\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:6483b357-5b4d-42a1-a95f-e1815c4dcb2e>\",\"WARC-Concurrent-To\":\"<urn:uuid:64596c09-6bee-4f4d-9503-b4ebec9213b6>\",\"WARC-IP-Address\":\"192.0.78.178\",\"WARC-Target-URI\":\"https://cloudstack.ninja/kde/python-dictionary-holding-wrong-values/\",\"WARC-Payload-Digest\":\"sha1:X62WWZUW664RLZ4YTTR6WNCPRUOGTQ2L\",\"WARC-Block-Digest\":\"sha1:25RDJCJEBIMUULQQ32SXLDR6YCTKI2HW\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2021/CC-MAIN-2021-21/CC-MAIN-2021-21_segments_1620243991641.5_warc_CC-MAIN-20210511025739-20210511055739-00170.warc.gz\"}"}