mirror of
https://github.com/TheAlgorithms/Python.git
synced 2024-12-05 02:40:16 +00:00
902fe1c907
* updated reversed words * fixup! Format Python code with psf/black push Co-authored-by: github-actions <${GITHUB_ACTOR}@users.noreply.github.com>
16 lines
342 B
Python
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()
|