LC 0824 [E] Goat Latin - codewithsenpai/algos Wiki

class Solution:
    def toGoatLatin(self, sentence: str) -> str:
        words = sentence.split(' ')
        
        res = []
        
        for i, x in enumerate(words):
            s = ''
            
            if x[0].lower() in 'aeiou':
                s = x + 'ma'
            else:
                s = x[1:len(x)] + x[0] + 'ma'
                
            s += 'a' * (i+1)
                
            res.append(s)
        
        return ' '.join(res)