reverse words in a string

Reverse Words in a String

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:

1
2
Input: "Let's take LeetCode contest"
Output: "s'teL ekat edoCteeL tsetnoc"

solution

1
2
3
4
5
6
7
8
9
str = "Let's take LeetCode contest"
list = str.split(' ')
result1 = []
result2 = ""
for w in list:
result1.append(w[::-1])
for word in result1:
result2+=word+" "
print(result2)

note

1
2
3
print(type(str.split(' ')))
>>class ''