DEV Community

loading...

Discussion on: Daily Challenge #39 - Virus

Collapse
hectorpascual profile image
Héctor Pascual

Python :

import re

def fix_virus(document):
    doc = document.lower().capitalize()
    return re.sub(r'ie','ei',doc)

Python one-liner :

fix_virus = lambda doc : re.sub(r'ie','ei',doc.lower().capitalize())
Collapse
bigj1m profile image
Jim Plourde

If it's a document, it will contains multiple sentences and capitalize is only uppercasing the first letter of a string

Collapse
hectorpascual profile image
Héctor Pascual

Ok then split document by lines and call the function :

document_splitted = document.split('\n')
for line in document_splitted:
    fix_virus(line)
    ....

Or capitalize each line of the document after lowering :)

Thread Thread
bigj1m profile image
Jim Plourde

Your solution is very good btw. Good job