CODING PRACTICE - 20 List Reverse
- Get link
- Other Apps
List Reverse
List Reverse
Given a list of words, write a program to reverse the words in the list.
Input
The first line of input will contain space-separated words, denoting the elements of the list.
Output
The output should be a single line containing a list with the elements in reverse order.
Explanation
For example, if the given sentence is the following.
Banana Apple Pomegranate Strawberry Grapes Orange
Your code should print the list by reversing the words in the given sentence. So the output should be
['Orange', 'Grapes', 'Strawberry', 'Pomegranate', 'Apple', 'Banana']
Sample Input 1Sample Output 1
Banana Apple Pomegranate Strawberry Grapes Orange
['Orange', 'Grapes', 'Strawberry', 'Pomegranate', 'Apple', 'Banana']
Sample Input 2Sample Output 2
Cricket Hockey Football Badminton Tennis Basketball Golf Volleyball Archery Boxing
['Boxing', 'Archery', 'Volleyball', 'Golf', 'Basketball', 'Tennis', 'Badminton', 'Football', 'Hockey', 'Cricket']
code:
a= input()
w = a.split()
re=w[::-1]
print(re)
Comments
Post a Comment