We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent e2a78d4 commit 2cff0b4Copy full SHA for 2cff0b4
strings/reverse_words_in_sentence.py
@@ -0,0 +1,25 @@
1
+"""
2
+reverse_words_in_sentence.py
3
+----------------------------
4
+Reverses the order of words in a given sentence.
5
+
6
+Example:
7
+ >>> reverse_words_in_sentence("hello world")
8
+ 'world hello'
9
10
+ >>> reverse_words_in_sentence("Python is fun")
11
+ 'fun is Python'
12
13
14
+def reverse_words_in_sentence(sentence: str) -> str:
15
+ """
16
+ Reverse the order of words in a sentence.
17
+ Words are separated by spaces.
18
19
+ words = sentence.strip().split()
20
+ return " ".join(reversed(words))
21
22
23
+if __name__ == "__main__":
24
+ sentence = input("Enter a sentence: ")
25
+ print(reverse_words_in_sentence(sentence))
0 commit comments