Reversing a List in Python
In Python, you can reverse the order of elements in a list by using the reverse method.
listname.reverse()
This method swaps the position of the first element with the last, the second element with the second-to-last, and so forth.
A Practical Example
Consider the following list:
year = [2010, 2011, 2012, 2013, 2014]
To reverse the list, you would type:
year.reverse()
After reversing, the list would look like this:
[2014, 2013, 2012, 2011, 2010]
The reverse method doesn't change the data within the list; it merely reverses the order of the elements.