forked from TheAlgorithms/Python
- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreverse_letters.py
More file actions
Latest commit
19 lines (16 loc) · 604 Bytes
/
Copy pathreverse_letters.py
File metadata and controls
19 lines (16 loc) · 604 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
defreverse_letters(input_str: str) ->str:
"""
Reverses letters in a given string without adjusting the position of the words
>>> reverse_letters('The cat in the hat')
'ehT tac ni eht tah'
>>> reverse_letters('The quick brown fox jumped over the lazy dog.')
'ehT kciuq nworb xof depmuj revo eht yzal .god'
>>> reverse_letters('Is this true?')
'sI siht ?eurt'
>>> reverse_letters("I love Python")
'I evol nohtyP'
"""
return" ".join([word[::-1] forwordininput_str.split()])
if__name__=="__main__":
importdoctest
doctest.testmod()