How can you obtain a list of words in reverse order from the string 'Python is fun'?
Understand the Problem
The question is asking how to manipulate a string in Python to create a list of its words in reverse order. It presents four different code options to achieve this and requires identifying the correct one.
Answer
' '.join(reversed('Python is fun'.split())) results in 'fun is Python'.
You can use ' '.join(reversed('Python is fun'.split())) to obtain the list of words in reverse order: 'fun is Python'.
Answer for screen readers
You can use ' '.join(reversed('Python is fun'.split())) to obtain the list of words in reverse order: 'fun is Python'.
More Information
By using the split(), reversed(), and join() functions, you can easily rearrange words in a string.
Tips
A common mistake is to try to reverse individual characters instead of reversing the whole list of words.
Sources
- Python: Reverse Order Of Words - string - Stack Overflow - stackoverflow.com