import random def bucket_sort(li,n=100,max_num=10000): buckets = [[] for _ in range(n)] for x in li: i = min(x // (max_num // n), n-1) buckets[i].append(x) for j in range(len(buckets[i])-1,0,-1): if buckets[i][j] < buckets[i][j-1]: buckets[i][j], buckets[i][j-1] = buckets[i][j-1],buckets[i][j] else: break li.clear() for b in buckets: li.extend(b) def main(): li = list(range(100)) random.shuffle(li) print(li) bucket_sort(li) print(li) if __name__ == '__main__': main()