1. Live a list of random numbers first
2, then to sort, put the big elements in the back, small elements placed in front, the final realization from small to large arrangement
First to survive a list of random numbers
Import random# Print (Sys.path) # print (__file__) L1 = []for i in range (6): i = Random.randrange (0,165535) L1.append (i) print (L1) [72764, 163851, 54255, 51053, 106289, 48579]
Then sort the list
r = Len (L1) for M in Range (r-1): a = 0 for n in range (r-1): if l1[a] > l1[a + 1]: Tmp_before = l1[a]
tmp_after = l1[a + 1] l1[a] = tmp_after l1[a + 1] = Tmp_before # print (L1) elif l1[a] = = L1[a + 1]: s = "l1[%s] and l1[%s] equal, this time without replacing"% (a,a+1) print (S.center (+, "-")) pass else: s = "l1[%s" is smaller than l1[%s], This time without replacing "% (a, a + 1) print (S.center (+,"-")) pass A + = 1print (L1) [48579, 51053, 54255, 72764, 106289, 16385 1]
Using Python for bubbling sorting