Skip to content

Latest commit

 

History

History
36 lines (19 loc) · 865 Bytes

Stop_gninnipS_My_sdroW.md

File metadata and controls

36 lines (19 loc) · 865 Bytes

CodeWars Python Solutions


Stop gninnipS My sdroW!

Write a function that takes in a string of one or more words, and returns the same string, but with all five or more letter words reversed (Just like the name of this Kata). Strings passed in will consist of only letters and spaces. Spaces will be included only when more than one word is present.

Examples: spinWords( "Hey fellow warriors" ) => returns "Hey wollef sroirraw" spinWords( "This is a test") => returns "This is a test" spinWords( "This is another test" )=> returns "This is rehtona test"


Given Code

def spin_words(sentence):
    pass

Solution

def spin_words(sentence):
    return " ".join([w[::-1] if len(w) >= 5 else w for w in sentence.split()])

See on CodeWars.com