0

I trying to write a program, which will correct errors in text file, for example TOm--> Tom, EUrope-->Europe, but if word has two letters, for example IT, program will ask the user if he wants to change second letter.I must use re.sub

import re



with open("file", 'r') as f:
    text=f.read()

for word in text.split(" "):
    if len(word)==2:
        x=int(input("DO you want to change second letter? (YES=1/N0=0):"))
        if x==1:
            lista2=re.sub('([A-Z][A-Z]+ )',lambda q: q.group(1).lower(),text)

    else:
        lista1 = re.sub('([A-Z][A-Z][a-z]+)', lambda q: q.group(1).lower(), text)

Issues with the code is that I got two small letters (tom not Tom), and the code doesn't change letters in words with length of 2.

ivan_pozdeev
  • 33,874
  • 19
  • 107
  • 152
pawelK
  • 131
  • 6

0 Answers0