DESCRIPTION:
Complete the function that accepts a string parameter, and reverses each word in the string. All spaces in the string should be retained.
Examples
"This is an example!" ==> "sihT si na !elpmaxe"
"double spaces" ==> "elbuod secaps"
def reverse_words(text):
ans=""
alist=text.split(' ')
print (alist)
for i in range(len(alist)):
alist[i]=alist[i][::-1]
print (alist)
for i in range(len(alist)):
ans+=alist[i]+' '
return ans[:-1]'알고리즘 문제 > CodeWar' 카테고리의 다른 글
| Are they the "same"? (0) | 2022.09.20 |
|---|---|
| Isograms (1) | 2022.09.19 |
| Array.diff (0) | 2022.09.19 |
| Get the Middle Character (1) | 2022.09.19 |
| Duplicate Encoder (0) | 2022.09.19 |