leetcode 824. Goat Latin 山羊拉丁文 python 字符串操作

所有Leetcode题目不定期汇总在 Github, 欢迎大家批评指正,讨论交流。
class Solution:
    def toGoatLatin(self, S):
        """
        :type S: str
        :rtype: str
        """
        # method one 
        dic = {'A','E','I','O','U'}
        words = S.split(' ')
        for index , word in enumerate(words):
            if word.capitalize()[0] in dic:
                words[index] += 'ma' + 'a'*(index+1)
            else:
                words[index] = word.replace(word[0],'',1) + word[0] + 'ma' + 'a'*(index+1)
        return ' '.join(words)      
        
所有Leetcode题目不定期汇总在 Github, 欢迎大家批评指正,讨论交流。

你可能感兴趣的:(【leetcode】,刷题总结,&,编程心得)