Stop Spinning My Words
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"
spinWords("This is a test") => "This is a test"
spinWords("This is another test") => "This is rehtona test"
Code:
- def spin_words(sentence):
- op=[]
- for x in sentence.split(" "):
- if len(x)>=5:
- op.append(x[::-1])
- else:
- op.append(x)
- return " ".join(op)
- print(spin_words("This is worden "))
- print(spin_words("This is another test"))
- print(spin_words("This is a test"))
0 Comments
Post a Comment