From aebf9bdaafbaa71ad4b5bf933ed2231ae7e4f731 Mon Sep 17 00:00:00 2001 From: Snimerjot Singh Date: Tue, 27 Oct 2020 09:35:37 +0530 Subject: [PATCH] Added reverse_letters.py (#3730) * Added reverse_letters.py * Update strings/reverse_letters.py Co-authored-by: Du Yuanchao Co-authored-by: Du Yuanchao --- strings/reverse_letters.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 strings/reverse_letters.py diff --git a/strings/reverse_letters.py b/strings/reverse_letters.py new file mode 100644 index 000000000..10b8a6d72 --- /dev/null +++ b/strings/reverse_letters.py @@ -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()