题解 | #翻转单词序列#

翻转单词序列

http://www.nowcoder.com/practice/3194a4f4cf814f63919d0790578d51f3

-- coding:utf-8 --

class Solution:
def ReverseSentence(self, s):
# write code here
l = s.split(" ")
l.reverse()
new_str = " ".join(l)
return new_str

根据“ ”来拆分string,函数会返回一个包含拆分开string的list

.split(" ")

在每一个列表的逗号处增加一个“ ”, 并合并返回一个string

" ".join(iterable)

可参考 https://www.runoob.com/python3/python3-string-join.html

全部评论

相关推荐

点赞 收藏 评论
分享
牛客网
牛客企业服务