Python/strings/reverse_words.py
Christian Clauss 1f8a21d727
Tighten up psf/black and flake8 (#2024)
* Tighten up psf/black and flake8

* Fix some tests

* Fix some E741

* Fix some E741

* updating DIRECTORY.md

Co-authored-by: github-actions <${GITHUB_ACTOR}@users.noreply.github.com>
2020-05-22 08:10:11 +02:00

19 lines
450 B
Python

# Created by sarathkaul on 18/11/19
# Edited by farnswj1 on 4/4/20
def reverse_words(input_str: str) -> str:
"""
Reverses words in a given string
>>> sentence = "I love Python"
>>> reverse_words(sentence) == " ".join(sentence.split()[::-1])
True
>>> reverse_words(sentence)
'Python love I'
"""
return " ".join(reversed(input_str.split(" ")))
if __name__ == "__main__":
print(reverse_words("INPUT STRING"))