编写一个函数,它接受一个或多个单词的字符串,并返回相同的字符串,但所有五个或多个字母的单词都颠倒过来

题目描述:

# 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"


我的解答:
def spin_word(str):
a = str.split()
for i in range(0, len(a)):
if len(a[i]) >= 5:
a[i] = ''.join(reversed(a[i]))
b = ' '.join(a)
return b
原文地址:https://www.cnblogs.com/wlj-axia/p/12654327.html