DEV Community

Discussion on: Daily Challenge #39 - Virus

Collapse
 
jmplourde profile image
Jean-Michel Plourde • Edited

Python

edit: I changed my code to only consider periods at the end of a word so words like nice.gif wouldn't be considered as the end of a sentence.

def antivirus(text):
    str_arr = text.lower().replace('ie', 'ei').split(" ")
    first = True
    for i, s in enumerate(str_arr):
        if first:
            str_arr[i] = s.capitalize()
        first = True if s[-1:] == '.' else False
    return " ".join(str_arr)
Collapse
 
hectorpascual profile image
Héctor Pascual

Nice, that way (checking words containing dots) you can check if it is needed to capitalize more than once in the same line, clever!!

Collapse
 
jmplourde profile image
Jean-Michel Plourde

I edited my answer so my code would not consider periods in the middle of a word to be the end of a sentence (ie: This file is named nice.gif and it is weird.)