Stop Spinning My Words

Stop spinning in python



Problem Statement

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 (like the name of this kata).

1.Strings passed in will consist of only letters and spaces.
2.Spaces will be included only when more than one word is present.


Examples:

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

Code:

  1. def spin_words(sentence):
  2.     op=[]
  3.     for x in sentence.split(" "):
  4.         if len(x)>=5:
  5.             op.append(x[::-1])
  6.         else:
  7.             op.append(x)
  8.     return " ".join(op)
  9. print(spin_words("This is worden "))
  10. print(spin_words("This is another test"))
  11. print(spin_words("This is a test"))