本人菜鸡,菜的一批,打卡分享思路
class Solution:
def toGoatLatin(self, sentence: str) -> str:
res = []
tail = 'a'
for word in sentence.split():
if word[0] in ['a','e', 'i', 'o', 'u', 'A', 'E','I', 'O', 'U']:
word += 'ma'
else:
word = word[1:]+ word [0] + 'ma'
word += tail
res.append(word)
tail += 'a'
return " ".join(res)
join()
join()方法获取可迭代对象中的所有项目,并将它们连接为一个字符串。必须将字符串指定为分隔符。
语法
string.join(iterable)