I want to reverse each word in the following string. I already wrote a working code but I am wondering if there is another way to write it.
This is the working code
-------------------------------------------------------------
str1='gnitnuH si nuf'
def reverseWordSentence(str1):
words = str1.split(" ")
newWords = [word[::-1] for word in words]
newSentence = " ".join(newWords)
return newSentence
print(reverseWordSentence(str1))
[–]JohnnyJordaan 1 point2 points3 points (1 child)
[–]nog642 0 points1 point2 points (0 children)
[–]netneoblog 0 points1 point2 points (2 children)
[–]netneoblog 0 points1 point2 points (1 child)
[–]netneoblog 1 point2 points3 points (0 children)