Skip to content

Latest commit

 

History

History
40 lines (22 loc) · 579 Bytes

Reverse_words.md

File metadata and controls

40 lines (22 loc) · 579 Bytes

CodeWars Python Solutions


Reverse words

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"

Given Code

def reverse_words(text):
    pass

Solution

def reverse_words(text):
  return " ".join([word[::-1] for word in text.split(" ")])

See on CodeWars.com