Reverse Words in a String III
Given a string, you need to reverse the order of characters in each word within a sentence while still preserving whitespace and initial word order.
Example 1:
Input:
"Let's take LeetCode contest"
Output:
"s'teL ekat edoCteeL tsetnoc"
class Solution(object):
def reverseWords(self, s):
"""
:type s: str
:rtype: str
"""
l=s.split()
l = map(lambda x: x[::-1], l)
return ' '.join(l)
#return ' '.join(x[::-1] for x in s.split())
Last updated
Was this helpful?