Python ProgrammingPython Programming

Capitalizes a string according to the Index positions in Python

def capitalize(s, ind):
    split_s = list(s)
    for i in ind:
        try:
            split_s[i] = split_s[i].upper()
        except IndexError:
            print('Index out of range : ', i)
    return "".join(split_s)


print(capitalize("abracadabra", [2, 6, 9, 10, 50]))
Output
Index out of range :  50
abRacaDabRA