[Python] Python - Read, Filter, Match & Write[Python] Python - Read, Filter, Match & Write

🪢

Hangman Solver

Week 47, 2026

def isMatch(a:str, b:str) -> bool: if len(a) == len(b): for i in range(len(a)): if (a[i] != b[i] and a[i] != '_'): return False return True return False def readToList(fileName:str) -> list[str | None]: data = [] try: file = open(fileName, 'r') for line in file: data.append(line.rstrip().lower()) file.close() print(f"[RTL] {len(data)} line read to list.") except Exception as e: print(e) return data def writeToFile(fileName:str, data:list[str]) -> None: try: file = open(fileName, 'w') for line in data: file.write(line+'\n') file.close() print("[WTF] Ans.txt made..") except Exception as e: print(e, '[WTF] File problem :/') def main() -> None: inputs = [ "a___e", "___z", "u___", "a_____a", "a_b___", "__oo__", "e_____t", "_y____", "pro____", "___________________" ] data = readToList("words-strict.txt") ans = [] for i in inputs: ans.append(f"--- Matches for {i} ---") for word in data: if isMatch(i, word): ans.append(word) writeToFile("ans.txt", ans) if __name__ == "__main__": main()