实现目标:英文句子中单词翻转。(例如:student. a am I翻转后是I am a student.)
python实现代码:
# -*- coding:utf-8 -*-
class Solution:
def ReverseSentence(self, s):
# write code here
s=s.split(' ')#将字符串用空格分隔开
return ' '.join(s[::-1])#将分割后的字符串顺序反过来,中间用空格连接