Skip to content

Commit 9a702e0

Browse files
SnimerrealDuYuanChao
authored andcommitted
Added reverse_letters.py (TheAlgorithms#3730)
* Added reverse_letters.py * Update strings/reverse_letters.py Co-authored-by: Du Yuanchao <[email protected]> Co-authored-by: Du Yuanchao <[email protected]>
1 parent 2f45d2a commit 9a702e0

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

Diff for: strings/reverse_letters.py

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
def reverse_letters(input_str: str) -> str:
2+
"""
3+
Reverses letters in a given string without adjusting the position of the words
4+
>>> reverse_letters('The cat in the hat')
5+
'ehT tac ni eht tah'
6+
>>> reverse_letters('The quick brown fox jumped over the lazy dog.')
7+
'ehT kciuq nworb xof depmuj revo eht yzal .god'
8+
>>> reverse_letters('Is this true?')
9+
'sI siht ?eurt'
10+
>>> reverse_letters("I love Python")
11+
'I evol nohtyP'
12+
"""
13+
return " ".join([word[::-1] for word in input_str.split()])
14+
15+
16+
if __name__ == "__main__":
17+
import doctest
18+
19+
doctest.testmod()

0 commit comments

Comments
 (0)