Import mathdef Radixsort (list, radix = ten): "Math.ceil for x rounding, and the result is a minimum integer not less than x. Math.log (x, a) returns the logarithm of log with a as the base x, and if not given a the bottom default is E ' ' k = Int (Math.ceil (Math.log (max (list), radix)) bucket = [[]f or I in range (radix)] "For I in range (1, k+1): A for J in list: # Math.floor (x) returns the largest integer of ≦x, example: Math.floor ( 3.4) = 3 Bucket[math.floor (J/(Radix * (i-1))% (radix))].append (j) #print (bucket) # Remove from list Element del list[:] for z in Bucket:print (z) List +=z print (list) Del z[:] return listlist = [434,24,657,976,2354,9,67,8099,4353,3453]print (Radixsort (list)) ' Import Randomimport Math Def radixsort (): #A =[random.randint (1,9999) for I in range (A =[5042,7431,3620,6306,858,8215,6438,2187,9830,2611) ] Print (A) for K in range (4): #4轮排序 s=[[] for I in range (Ten)] for I in A: # 10**k cleverly put k=0 ask Solved the S[math.floor (i/(10**k)%10)].append (i)# s = [[[a,b,c],[]], B = [A,b,c],a=a. A=[a for B under s for a in b] return Aprint (Radixsort ()) "
06 Cardinality Sorting