python 把英文转换成 "Simple Pig Latin" 儿童黑话
要求:
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.
SRE实战 互联网时代守护先锋,助力企业售后服务体系运筹帷幄!一键直达领取阿里云限量特价优惠。每个单词的第一个字母移动到最后,符号不变.比如上面那句话转变过来就是:
"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())))
缺点:
英文的逗号紧贴上句的最后一个单词,可能会出问题,不过测试通过了,测试句子里只是单句.

更多精彩