【发布时间】:2020-12-29 07:33:42
【问题描述】:
让我们创建一个将文本转换为猪拉丁语的函数:一个简单的文本转换,它修改每个单词,将第一个字符移到末尾,并将“ay”附加到末尾。例如,python 以 ythonpay 结尾。
def pig_latin(text):
list=[]
string=""
# Separate the text into words
for word in text.split():
list.append(word[1:]+word[0]+"ay")
# Create the pig latin word and add it to the list
# Turn the list back into a phrase
for n in list:
string = string + n +" "
return string.rstrip()
print(pig_latin("hello how are you")) # Should be "ellohay owhay reaay ouyay"
print(pig_latin("programming in python is fun")) # Should be "rogrammingpay niay ythonpay siay unfay"
【问题讨论】:
标签: python string list methods append