Learnerslesson
   JAVA   
  SPRING  
  SPRINGBOOT  
 HIBERNATE 
  HADOOP  
   HIVE   
   ALGORITHMS   
   PYTHON   
   GO   
   KOTLIN   
   C#   
   RUBY   
   C++   




PYTHON - REVERSE A LIST


How to reverse a List?


Reversal of a List can be done using 'reverse( )' method. It is independent of the alphabets.And is not a sort. It is just a reversal.


Example :


x = ["Mohan", "Kriti", "Salim"] 
x.reverse()
print("The List in reversed order is ",x) 


Output :



  The List in reversed order is ['Salim', 'Kriti', 'Mohan']

So, in the above code we have created a 'List' and initialised to the variable 'x'.


x = ["Mohan", "Kriti", "Salim"]

Below is how the values are positioned in the List,


java_Collections

Then we have used the 'reverse( )' Function to reverse the elements of the List 'x'.


x.reverse( )

And the List 'x' gets sorted in descending order with 'Salim' as the first value, 'Mohan' second and 'Kriti' as the third.


java_Collections

And we get the below output.


The List in reversed order is ['Salim', 'Kriti', 'Mohan']