Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- words = [
- 'tim',
- 'for',
- 'print',
- '1234567890',
- '321',
- '000',
- ]
- def check_word(operator: str):
- probability_map = {}
- for word in words:
- coincidence = 0
- len_word = len(word)
- len_operator = len(operator)
- if len_word == len_operator:
- for op_symbol, w_symbol in zip(operator, word):
- if w_symbol == op_symbol:
- coincidence += 1
- else:
- continue
- if coincidence == 0:
- continue
- probability_map[word] = 100 / len_word * coincidence, coincidence
- if probability_map:
- possible_word = sorted(probability_map)[0]
- percent_probability, coincidence = probability_map[possible_word]
- if percent_probability > 75 or len(possible_word) - coincidence <= 2:
- return possible_word
- else:
- return
- if __name__ == '__main__':
- for word in ['ti2', 'fi2', '123', '1234567990', 'prinr', 'Ti2', 'ris', 'qqq']:
- possible_word = check_word(word)
- if possible_word is not None:
- print(f'Вы написали: "{word}", возможно Вы имели ввиду: {possible_word}')
- else:
- print(f'Слова {word} нет в словаре!')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement