Skip to content

Latest commit

 

History

History
69 lines (40 loc) · 1.19 KB

Correct_the_mistakes_of_the_character_recognition_software.md

File metadata and controls

69 lines (40 loc) · 1.19 KB

CodeWars Python Solutions


Correct the mistakes of the character recognition software

Character recognition software is widely used to digitise 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 digitised character recognition softwares often make mistakes.

Your task is correct the errors in the digitised text. You only have to handle the following mistakes:

  • S is misinterpreted as 5
  • O is misinterpreted as 0
  • I is misinterpreted as 1

The test cases contain numbers only by mistake.


Given Code

def correct(string):
    pass

Solution 1

def correct(string):
    mis = {"0":"O", "5":"S", "1":"I"}
    for c in string:
        if c in mis:
            string = string.replace(c, mis[c])
    return string

Solution 2

def correct(string):
    return string.translate(str.maketrans("501", "SOI"))

Solution 3

def correct(string):
    return string.replace('1','I').replace('0','O').replace('5','S')

See on CodeWars.com