mirror of
https://github.com/TheAlgorithms/Python.git
synced 2024-11-24 05:21:09 +00:00
3d129a4964
* Create Python/quantum/README.md Started at #1831 * fixup! Format Python code with psf/black push Co-authored-by: github-actions <${GITHUB_ACTOR}@users.noreply.github.com>
22 lines
498 B
Python
22 lines
498 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'
|
|
"""
|
|
input_str = input_str.split(" ")
|
|
new_str = list()
|
|
|
|
return " ".join(reversed(input_str))
|
|
|
|
|
|
if __name__ == "__main__":
|
|
print(reverse_words("INPUT STRING"))
|