from collections import defaultdict
words_list = ['ALLY', 'BETA', 'COOL', 'DEAL', 'ELSE', 'FLEW', 'GOOD', 'HOPE', 'IBEX']
def make_primary_dict(user_input, words_list):
guess_dict = defaultdict(list)
for word in words_list:
new_word = []
for ch in word:
if ch != user_input:
ch = '-'
new_word.append(ch)
else:
new_word.append(ch)
guess_dict[(''.join(new_word))] += [word]
return dict(guess_dict)
>>> make_primary_dict('E', words_list)
{'----': ['ALLY', 'COOL', 'GOOD'], '-E--': ['BETA', 'DEAL'], 'E--E': ['ELSE'], '--E-': ['FLEW', 'IBEX'], '---E': ['HOPE']}
def make_primary_dict(user_input, words_list):
guess_dict = defaultdict(list)
for word in words_list:
guess_dict[''.join(c if c == user_input else "-" for c in word)] += [word]
return dict(guess_dict)
>>> make_primary_dict('E', words_list)
{'----': ['ALLY', 'COOL', 'GOOD'], '-E--': ['BETA', 'DEAL'], 'E--E': ['ELSE'], '--E-': ['FLEW', 'IBEX'], '---E': ['HOPE']}