Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/sorting/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用python函数进行基数排序_Python_Sorting_Radix Sort - Fatal编程技术网

使用python函数进行基数排序

使用python函数进行基数排序,python,sorting,radix-sort,Python,Sorting,Radix Sort,我使用这段代码在python中对带有基数排序的列表进行排序 def radix(self, a): len_a = len(a) modulus = 10 div = 1 while True: '''DECLARATION OF BUCKETS''' new_list = [[], [], [], [], [], [], [], [], [], []] for

我使用这段代码在python中对带有基数排序的列表进行排序

def radix(self, a):
        len_a = len(a)
        modulus = 10
        div = 1
        while True:
            '''DECLARATION OF BUCKETS'''
            new_list = [[], [], [], [], [], [], [], [], [], []]
            for value in a:
                least_digit = value % modulus
                least_digit /= div
                new_list[least_digit].append(value)
            modulus = modulus * 10
            div = div * 10

            if len(new_list[0]) == len_a:
                '''RETURN THE LIST WHEN SORTED'''
                return new_list[0]

            a = []

            rd_list_append = a.append

            for x in new_list:
                for y in x:
                    rd_list_append(y)
我不明白这些台词的作用

            a = []

            rd_list_append = a.append

            for x in new_list:
                for y in x:
                    rd_list_append(y)
我知道for循环是如何工作的,但它是什么 rd_列表_追加(y)
请帮帮我。我是python新手

好的,这就是为什么他们告诉你不要从互联网上复制作业代码的原因

这部分代码基本上是修改原始列表以进行部分排序(一轮基数排序)。您可以将“rd_list_append”视为指向列表“a”的append函数的指针

您也可以在循环中直接执行a.append(y)

你从哪里得到这个密码的?