import million.analyze.message_evaluation as msg_val def check_extra_or_missing_letter(word, reference): len_word = len(word) len_ref = len(reference) if abs(len_word - len_ref) != 1: return False shortest = word if len_word < len_ref else reference longest = word if len_word > len_ref else reference for i in range(len(shortest)): if shortest[i] != longest[i]: return shortest[i:] == longest[i + 1 :] return True def check_single_letter_differ(word, reference): return sum(1 for x, y in zip(reference, word) if x != y) == 1 def check_letter_swap(word, reference): if len(word) != len(reference): return False for i in range(len(word) - 1): if word[i] != reference[i]: return word[i + 1] + word[i] + word[i + 2 :] == reference[i:] return False def check_typo(word, reference): if len(reference) == len(word): return check_single_letter_differ(word, reference) or \ check_letter_swap(word, reference) else: return check_extra_or_missing_letter(word, reference) def find_value_around_index(messages, value, idx, amplitude) -> int: check_value = lambda x: msg_val.get(messages[x]) == value if check_value(idx): return idx for offset in range(1, amplitude): o_idx = idx + offset * +1 if check_value(o_idx): return o_idx o_idx = idx + offset * -1 if check_value(o_idx): return o_idx return -1