Added reverse_letters.py (#3730)

* Added reverse_letters.py

* Update strings/reverse_letters.py

Co-authored-by: Du Yuanchao <shellhub.me@gmail.com>

Co-authored-by: Du Yuanchao <shellhub.me@gmail.com>
This commit is contained in:
Snimerjot Singh 2020-10-27 09:35:37 +05:30 committed by GitHub
parent a5aef147e9
commit aebf9bdaaf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -0,0 +1,19 @@
def reverse_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] for word in input_str.split()])
if __name__ == "__main__":
import doctest
doctest.testmod()