June 12, 2019 - start to record and share in the learning experience --Python3.7 sort the list

Python sort the list sorted according to whether the recovery can be divided into: permanent and temporary sort order. 

Python sorted list can be used according to different functions can be divided into: sort (), sorted (), reverse ().

 

The following specific about the use of these three functions:

1. Use the sort () to sort the list permanently

my_love = [ 'sleep', ' weekend', 'games', 'learning', 'travel'] # define a list 
my_love.sort () # permanent list alphabetically sorted
print (my_love) # print authentication sorted list results
my_love.sort (reverse = True) # on the list in reverse order permanent letters sorted
print (my_love) # printing list sorting result verification

Note: If using a statement like print, print result -> None

print(my_love.sort())

2. Use the sorted () to sort the list by temporary

print (sorted (my_love)) # list alphabetically temporary sort 
print (sorted (my_love, reverse = True)) # list according to the alphabetical reverse order temporary sort
print (my_love) # Printing List authentication list sorted no change

3. Use the order reverse () inverted list

the order my_love.reverse () # inverted list 
print (my_love) # verification sort result

my_love.reverse () # reversed again in the order list, the order of the list is restored
print (my_love) # sorting result verification

Note: If using a statement like print, print result -> None

print(my_love.reverse())

Guess you like

Origin www.cnblogs.com/shirley-yang/p/11012669.html