Guess the Word LeetCode solution in Python
1class Solution:2def findSecretWord(self, words: List[str], master: "Master") -> None:3k = 1 # for tracing the number of loops4matches = 05blacklists = [[] for i in range(6)]67while matches != 6:8n = len(words)9r = random.randint(0, n - 1)10matches = master.guess(words[r])11key = words[r]12# print(k, n, r, matches, key)1314words.pop(r)1516if matches == 0:17for i in range(6):18blacklists[i].append(key[i])19# print(blacklists)2021elif matches > 0 and matches < 6:22candidates = []23for i in range(n - 1):24count = 025for j in range(6):26if words[i][j] not in blacklists[j] and words[i][j] == key[j]:27count += 128if count >= matches:29candidates.append(words[i])3031words = candidates.copy()32# print(words)3334k += 1