Array content double-digit ordering:
#Coding:utf-8PrintU"English"a= [' the',' One',' -',' the',' A',' +']b=0c=0PrintAI=0 forJinchRange (len (a)): forIinchRange (0,len (a)-1): ifA[i] > A[i+1]: b=A[i] A[i]=a[i+1] A[i+1]=b#A.sort ()#a.sort (key = len)PrintA
Array content differences in number of digits ascending: A.sort () method
#Coding:utf-8PrintU"English"a= [' the','1',' -','5',' A','3']a.sort () a.sort (Key=len)PrintA
#[' 1 ', ' 3 ', ' 5 ', ' 13 ', ' 15 ', ' 61 ']
The Sort method also has two optional parameters: Key and reverse
Key must provide a method that is called during the sort process when it is used
Reverse to sort in descending order of the same number of digits, you need to provide a Boolean value:
y = [3, 2, 8, 0, 1= True)print#[8, 3, 2, 1, 0]
Python Bubble sort applies only the same number of digits, the number of digits is different with the A.sort () method