Python Reverse a List
The reverse() method in list class reverses the order of items in the list. The item in last index is relocated to 0th index, and one originally at index 0 goes to the last position.
Syntax
list.reverse()
Return value
This method doesn't return anything as the order is reversed in-place.
Example
The following example demonstrates how you can reverse a list −
lst = [25, 12, 10, -21, 10, 100]
print ("lst:", lst)
lst.reverse()
print ("Reversed list:", lst)
It will produce the following output −
lst: [25, 12, 10, -21, 10, 100] Reversed list: [100, 10, -21, 10, 12, 25]
python_list_methods.htm
Advertisements