将序列按空格读成list,再用reverse()函数翻转list,最后用join把list变成str。
class Solution:
def ReverseSentence(self, s):
# write code here
if not s:
return s
list1 = s.split()
if len(list1)==0:
return s
list1.reverse()
return ' '.join(list1)