-
-
Notifications
You must be signed in to change notification settings - Fork 47.1k
Reverse Words #1581
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Reverse Words #1581
Changes from all commits
fa0f04c
c1d4137
95e6937
b097ab5
91c60cd
74ea352
e9efb67
0e91cba
8848185
2a820be
74d7eb7
84226e4
956aa71
dd3dca3
a6ebd2b
451d296
fce2680
40903de
bc60cb3
fd6639a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# Created by sarathkaul on 18/11/19 | ||
|
||
|
||
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() | ||
|
||
for a_word in input_str: | ||
new_str.insert(0, a_word) | ||
|
||
return " ".join(new_str) | ||
Comment on lines
+14
to
+19
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I just got the idea that There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Line 8 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I noticed it being used as a doctest, and NOT the actual function. 😅 Hence, the comment. |
||
|
||
|
||
if __name__ == "__main__": | ||
print(reverse_words("INPUT STRING")) |
Uh oh!
There was an error while loading. Please reload this page.