Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

count_analysis.py 1.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. def check_extra_or_missing_letter(word, reference):
  2. len_word = len(word)
  3. len_ref = len(reference)
  4. if abs(len_word - len_ref) != 1:
  5. return False
  6. shortest = word if len_word < len_ref else reference
  7. longest = word if len_word > len_ref else reference
  8. for i in range(len(shortest)):
  9. if shortest[i] != longest[i]:
  10. return shortest[i:] == longest[i + 1 :]
  11. return True
  12. def check_single_letter_differ(word, reference):
  13. return sum(1 for x, y in zip(reference, word) if x != y) == 1
  14. def check_letter_swap(word, reference):
  15. if len(word) != len(reference):
  16. return False
  17. for i in range(len(word) - 1):
  18. if word[i] != reference[i]:
  19. return word[i + 1] + word[i] + word[i + 2 :] == reference[i:]
  20. return False
  21. def check_typo(word, reference):
  22. if len(reference) == len(word):
  23. return _check_single_letter_differ(word, reference) or \
  24. _check_letter_swap(word, reference)
  25. else:
  26. return _check_extra_or_missing_letter(word, reference)
  27. def find_value_around_index(messages, value, idx, amplitude) -> int:
  28. check_value = lambda x: msg_val.get(messages[x]) == value
  29. if check_value(idx):
  30. return idx
  31. for offset in range(1, amplitude):
  32. o_idx = idx + offset * +1
  33. if check_value(o_idx):
  34. return o_idx
  35. o_idx = idx + offset * -1
  36. if check_value(o_idx):
  37. return o_idx
  38. return -1