How to reverse each word in a string with Python

1 Answer

0 votes
def ReverseEachWordInAString(s):
    words = s.split(" ")
     
    reversedWordsList = [word[::-1] for word in words]

    s = " ".join(reversedWordsList)
 
    return s
 

s = "java c++ rust python c#"

print(ReverseEachWordInAString(s))



'''
run:

avaj ++c tsur nohtyp #c

'''

 



answered Aug 30, 2024 by avibootz
...