因爲我只是一個初學者,所以我在Python 3.5中創建了一個小型單字豬拉丁語翻譯器。我有我的粗略代碼,但我真的很喜歡你的意見,如何使它更緊湊,pythonic,和「優雅」(即專業)。任何幫助表示讚賞,謝謝!在Python中「清理」基本豬拉丁語翻譯器
#Converts a word into pig latin, needs to be cleaned up
def pig_latin(word):
word = list(word)
first_letter = word[0]
del word[0]
word.insert(len(word),first_letter)
word.insert(len(word),'ay')
print(''.join(word))
那麼對於初學者'x.insert(LEN(X)中,y)'相當於'x.append(Y)'。 –
添加文檔字符串,以描述輸入和預期輸出。 –
由於你有工作代碼,這可能更適合於[代碼評論](http://codereview.stackexchange.com/) –