loading...

re: Daily Challenge #39 - Virus VIEW POST

FULL DISCUSSION
 

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)
 

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

 

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.)

Code of Conduct Report abuse