Skip to content

Commit

Permalink
Update reverse_words.py (TheAlgorithms#1825)
Browse files Browse the repository at this point in the history
The following update results in less lines of code and faster performance while preserving functionality.
  • Loading branch information
farnswj1 authored Apr 4, 2020
1 parent 9b376a5 commit 20c2db0
Showing 1 changed file with 2 additions and 4 deletions.
6 changes: 2 additions & 4 deletions strings/reverse_words.py
Original file line number Diff line number Diff line change
@@ -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:
Expand All @@ -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__":
Expand Down

0 comments on commit 20c2db0

Please sign in to comment.