forked from TheAlgorithms/Python
- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreverse_long_words.py
More file actions
Latest commit
21 lines (17 loc) · 605 Bytes
/
Copy pathreverse_long_words.py
File metadata and controls
21 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
defreverse_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]) iflen(word) >4elsewordforwordinsentence.split()
)
if__name__=="__main__":
importdoctest
doctest.testmod()
print(reverse_long_words("Hey wollef sroirraw"))