I have a function which is supposed to get a word and choose one of its letters by random. I also have a list of already chosen letters. If the chosen letter already exists in this list, I use recursion to choose another letter:
def choose(word, chosen_list):
chosen_letter = random.choice(word)
if chosen_letter not in chosen_list:
print("Found")
else:
choose(word, chosen_list)
The problem is that when choose function is called multiple times, I encounter an error:
chosen_letter = random.choice(word)
File "...\random.py", line 259, in choice
i = self._randbelow(len(seq))
File "...\random.py", line 232, in _randbelow
if type(random) is BuiltinMethod or type(getrandbits) is Method:
RecursionError: maximum recursion depth exceeded while calling a Python object
Why this is happening?