class Solution(object):
def reverseWords(self, s):
"""
:type s: str
:rtype: str
"""
list = s.split(" ")
for i in range(len(list)):
list[i] = list[i][::-1]
return " ".join(list)
class Solution(object):
def reverseWords(self, s):
"""
:type s: str
:rtype: str
"""
list = s.split(" ")
str = map(reversed,list)
s = map("".join,str)
s = " ".join(s)
return s
翻转字符串:
s[::-1]
is fastest;- a slower approach (maybe more readable, but that’s debatable) is
''.join(reversed(s))
.
" ".join(list)
将list转换成str