GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — Python/strings/reverse_long_words.py at master · Uncodedtech/Python Expand file tree/ Copy pathreverse_long_words.pyMore file actions 21 lines (17 loc) · 605 Bytes / Copy pathreverse_long_words.pyFile metadata and controls21 lines (17 loc) · 605 Bytes 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 def reverse_long_words(sentence: str) -> str: """ Reverse all words that are longer than 4 characters in a sentence. >>> reverse_long_words("Hey wollef sroirraw") 'Hey fellow warriors' >>> reverse_long_words("nohtyP is nohtyP") 'Python is Python' >>> reverse_long_words("1 12 123 1234 54321 654321") '1 12 123 1234 12345 123456' """ return " ".join( "".join(word[::-1]) if len(word) > 4 else word for word in sentence.split() ) if __name__ == "__main__": import doctest doctest.testmod() print(reverse_long_words("Hey wollef sroirraw")) |
| You are visitor 01402520 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |