正常的def pig_it(): word = ‘Pig latin is cool ‘ wordList = word.split() re = ‘‘ for item in wordList: if item.isalpha(): head = item[1:] ass = item[0]+‘ay‘ temp = head+ass+‘ ‘ else: temp = item+‘‘ re += temp re.strip() print(re)骚一点的def pig_it_final(): word = ‘Pig latin is cool !‘ print(‘ ‘.join([item[1:] +item[0]+‘ay‘ if item.isalpha() else item for item in word.split()])) return ‘ ‘.join([item[1:] +item[0]+‘ay‘ if item.isalpha() else item for item in word.split()]) if __name__ == ‘__main__‘: pig_it_final()
时间: 2024-10-15 15:36:48