From 20c2db0de4bb4f73db3053b13280bed8dee30cf4 Mon Sep 17 00:00:00 2001 From: farnswj1 <54967482+farnswj1@users.noreply.github.com> Date: Sat, 4 Apr 2020 01:01:37 -0400 Subject: [PATCH] Update reverse_words.py (#1825) The following update results in less lines of code and faster performance while preserving functionality. --- strings/reverse_words.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/strings/reverse_words.py b/strings/reverse_words.py index 123b07440..547dda93d 100644 --- a/strings/reverse_words.py +++ b/strings/reverse_words.py @@ -1,4 +1,5 @@ # Created by sarathkaul on 18/11/19 +# Edited by farnswj1 on 4/4/20 def reverse_words(input_str: str) -> str: @@ -13,10 +14,7 @@ def reverse_words(input_str: str) -> str: input_str = input_str.split(" ") new_str = list() - for a_word in input_str: - new_str.insert(0, a_word) - - return " ".join(new_str) + return ' '.join(reversed(input_str)) if __name__ == "__main__":