-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcorrect_mistakes.py
60 lines (42 loc) · 1.39 KB
/
correct_mistakes.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#!/usr/bin/env python3
"""Digital Mistakes kata.
Correct the mistakes of the character recognition software.
Share this kata:
Character recognition software is widely used to digitize printed texts.
Thus the texts can be edited, searched and stored on a computer.
When documents (especially pretty old ones written with a typewriter), are
digitized character recognition softwares often make mistakes.
Your task is correct the errors in the digitized text.
You only have to handle the following mistakes:
* S is misinterpreted as 5
* O is misinterpreted as 0
* I is misinterpreted as 1
"""
import re
class Corrections:
"""Corrections Class."""
corrections_map = {
'5': 'S',
'0': 'O',
'1': 'I',
}
@classmethod
def correct(self, word: str) -> str:
"""Correct the mistakes of the character recognition software.
:return: String of the corrected word.
"""
for k, v in self.corrections_map.items():
word = re.sub(k, v, word)
return word
def main():
"""Correct Mistakes Main function."""
word_list = ['0UTD00R5',
'1NL1NE',
'0NL1NE',
'1NPUT',
'501L',
'01L5', ]
for word in word_list:
print(Corrections.correct(word))
if __name__ == "__main__":
main()