Untitled

 avatar
unknown
python
a year ago
1.1 kB
3
Indexable
Write a function that takes in a string of one or more words, and returns the same string, but with all words that have five or more letters 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:

"Hey fellow warriors"  --> "Hey wollef sroirraw" 
"This is a test        --> "This is a test" 
"This is another test" --> "This is rehtona test"
def spin_words(sentence):
    # Your code goes here
    """
    در این کد ابتدا با استفاده از اسپلیت هر کلمه را بررسی کردیم که ببینم طولش بیشتر از پنج هست یا خیر در کنار یک حلقه،
    در ادامه اون کلمه رو برعکسش کردیم و بدون تغییر کلمات دیگر اون رو در جمله اصلی گذاشتیم

    """

    word = sentence.split()
    revers=[]
    for i in word:
        if len(i)>=5:
            revers.append(i)
    for r in revers:
        b=r[::-1]
    c=sentence.replace(r,b)
    return c
Leave a Comment