Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

Complete the function that accepts a string parameter, and reverses each word in the string. All spaces in the string should be retained.

# 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):
    return ' '.join([i[-1::-1] for i in text.split(" ")])
Source by www.geeksforgeeks.org #
 
PREVIOUS NEXT
Tagged: #Complete #function #accepts #string #reverses #word #All #spaces #string
ADD COMMENT
Topic
Name
9+4 =