How is it and can it be optimised? sentence = input(Enter a sentence you want to convert to pig latin: )sentence = sentence.split()for i in range(len(sentence)):    if sentence[i][0] in aeiou:        sentence[i] += 'yay'    else:        sentence[i]=sentence[i][1:]+sentence[i][0]        sentence[i]+='ay'sentence = ' '.join(sentence)print(sentence)
Pig Latin converter in Python
python;performance;pig latin
You don't actually care about indexes during the iteration; you just want the contents. The loop would be better written assentence = input()for word in sentence.split():    if word[0] in aeiou:        How would you reassemble the results?  Noting that each word can be translated independently, I would define a function for that, then use a generator expression.def pig_latin(word):    if word[0] in aeiou:        return word + 'yay'    else:        return word[1:] + word[0] + 'ay'sentence = input(Enter a sentence you want to convert to pig latin: )print(' '.join(pig_latin(word) for word in sentence.split()))