Demo entry 6626540

Python

   

Submitted by anonymous on Jun 25, 2017 at 20:05
Language: Python. Code size: 523 Bytes.

def spin_words(sentence):
    sentence = sentence.split(' ')
    cache = []
    for w in sentence:
        if len(w) >= 5:
            cache.append(''.join(v for v in w[::-1]))
        else:
            cache.append(w)
    return ' '.join(v for v in cache)

# Other way of doing it on one line


def spin_words2(sentence):
    return ' '.join(word if len(word) < 5 else word[::-1] for word in sentence.split())


print(spin_words2("Welcome hell poop pooped"))
print(spin_words("Welcome hell poop pooped"))

This snippet took 0.00 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).