Reverse () method
Reverses the order of the elements in the list, such as the following
>>> x = [1,5,2,3,4]
>>> X.reverse ()
>>> x
[4, 3, 2, 5, 1]
Reverse list reversal sort : The order of the elements in the original list is re-deposited from left to right without sorting the parameters in the List. If you need to organize the parameters in the list, you need to sort the list in a different sort order.
Sort () Sorting method
This function method sorts the contents of the list forward, and the sorted new list overwrites the original list (the ID remains the same), that is, the sort method is to directly modify the list ordering Method.
>>> A = [5,7,6,3,4,1,2]
>>> A.sort ()
>>> A
[1, 2, 3, 4, 5, 6, 7]
Many Python beginners are confused about the sort () method when playing snake Nets. Sometimes you need a sorted list, and then you want to save the original unordered lists, and they do the following:
>>> A = [5,7,6,3,4,1,2]
>>> B = A.sort ()
>>> Print B
None
At this point the problem arises, and variable B gets a null Value. What if you want to get a sorted list and want to keep the original list? The list sorted () method can be implemented for YOU.
Sorted () Method
That is, you can keep the original list, and you can get the sorted list sorted () operation method as Follows:
>>> A = [5,7,6,3,4,1,2]
>>> B = Sorted (a)
>>> A
[5, 7, 6, 3, 4, 1, 2]
>>> b
[1, 2, 3, 4, 5, 6, 7]
The sorted () method can be used in a sequence of any data type and is always returned in a list form:
>>> Sorted (' iplaypython.com ')
['. ', ' A ', ' C ', ' H ', ' I ', ' l ', ' m ', ' n ', ' o ', ' o ', ' P ', ' P ', ' t ', ' y ', ' y ']
This article explains the most basic sorting methods of the Python list, as well as more advanced sorting methods, such as the ability to include sort criteria within a method, which are described in the list advanced sorting methods Article.
Play Snake net article, reprint please indicate source and source Url: http://www.iplaypython.com/jinjie/jj114.html
Python list sort reverse, sort, sorted how-to