要求:
Move the first letter of each word to the end of it, then add "ay" to the end of the word. Leave punctuation marks untouched.
每个单词的第一个字母移动到最后,符号不变.比如上面那句话转变过来就是:
"oveMay hetay irstfay etterlay foay acheay ordway otay hetay ndeay foay tiay"
实现:
def pig_it(text):
import string
pig_suffix= "ay"
return " ".join(list(map(lambda x: x[1:]+x[0]+pig_suffix if x not in string.punctuation else x,text.split())))
缺点:
英文的逗号紧贴上句的最后一个单词,可能会出问题,不过测试通过了,测试句子里只是单句.