Python/strings/reverse_words.py
Du Yuanchao 902fe1c907
Fixed reverse words algorithm (#2469)
* updated reversed words

* fixup! Format Python code with psf/black push

Co-authored-by: github-actions <${GITHUB_ACTOR}@users.noreply.github.com>
2020-09-24 19:12:52 +08:00

16 lines
342 B
Python

def reverse_words(input_str: str) -> str:
"""
Reverses words in a given string
>>> reverse_words("I love Python")
'Python love I'
>>> reverse_words("I Love Python")
'Python Love I'
"""
return " ".join(input_str.split()[::-1])
if __name__ == "__main__":
import doctest
doctest.testmod()