I want to change the second last letter of each word in capital letter. but when my sentence contains a word with one letter the program gives an error of (IndexError: string index out of range). Here is my code. It works with more than one letter words. if I write, for example, str="Python is best programming language" it will work because there is not any word with (one) letter.
str ="I Like Studying Python Programming"
array1=str.split()
result =[]
for i in array1:
result.append(i[:-2].lower()+i[-2].upper()+i[-1].lower())
print(" ".join(result))