标签:odi rip pytho strip() elf 翻转单词 reverse 思路 else
思路:用到了split join等内置函数,之后再补充不用内置函数的方法吧
# -*- coding:utf-8 -*-
class Solution:
def ReverseSentence(self, s):
# write code here
if s == "":
return ""
out = s.split()[::-1]
if out == []:
return s
else:
return " ".join(out)
方法2:
class Solution:
def ReverseSentence(self, s):
return " ".join(s.split()[::-1]) if s.strip() != "" else s
标签:odi rip pytho strip() elf 翻转单词 reverse 思路 else
原文地址:https://www.cnblogs.com/dolisun/p/11334029.html