Skip to content

Instantly share code, notes, and snippets.

@kkt-ee
Created January 2, 2020 14:33
Show Gist options
  • Save kkt-ee/799b2b60bdf3c0a76be42ef04efc4f7b to your computer and use it in GitHub Desktop.
Save kkt-ee/799b2b60bdf3c0a76be42ef04efc4f7b to your computer and use it in GitHub Desktop.
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" ) => r…
def spin_words(sentence):
# Your code goes here
words = sentence.split(' ')#[::-1]
newL = list()
for word in words:
newL.append(word) if len(word)<5 else newL.append(word[::-1])
return ' '.join(newL)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment