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.
讲一句话中的每一个单词首字母移到末尾,并在最后加上’ay’, 标点符号忽略。

Examples 举例

pig_it(‘Pig latin is cool’) # igPay atinlay siay oolcay
pig_it(‘Hello world !’) # elloHay orldway !

源码:

def pig_it(text):
    wlist = text.split()
    nlist = []
    nw = ''
    for w in wlist:
        if w.isalnum():
            nw = w[1:]+w[0]+'ay'
        else:
            nw = w
        nlist.append(nw)
    return ' '.join(nlist)

你可能感兴趣的:(Python学习)