Reverse strings
Statement
Reverse the strings of a sentence.
Procedure
- Retrieve the sentence that is in argument
- Remove spaces with .split()
- Use the reverse method
- Return the sentence
Schema

Solution 1
1def reverse_string(sentence):
2
3 words = sentence.split(" ")
4
5 result = " ".join(reversed(words))
6 print(result)
Complexity
O(n) : n grows proportionally to the size of the input.
Solution 2
1def reverse_string(sentence):
2
3 words = sentence.split()[::-1]
4
5 new_sentence = []
6
7 for i in words:
8 new_sentence.append(i)
9
10 print(" ".join(new_sentence))
Complexity
O(n) : n grows proportionally to the size of the input.