2019-11-18 11:47:26 +00:00
|
|
|
# Created by sarathkaul on 18/11/19
|
2020-04-04 05:01:37 +00:00
|
|
|
# Edited by farnswj1 on 4/4/20
|
2019-11-18 11:47:26 +00:00
|
|
|
|
|
|
|
|
|
|
|
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()
|
|
|
|
|
2020-04-04 05:01:37 +00:00
|
|
|
return ' '.join(reversed(input_str))
|
2019-11-18 11:47:26 +00:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
print(reverse_words("INPUT STRING"))
|