2014-10-17 63 views
0

我使用這個代碼在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_list_append(y) 請幫助我。我是python的新手。

+0

你從哪裏得到這段代碼? – Wajahat 2014-10-17 06:21:41

回答

0

好的,這就是爲什麼他們告訴你不要從互聯網上覆制代碼作業。

這部分代碼基本上是修改原始列表進行部分排序(一輪基數排序)。你可以把'rd_list_append'看作是附加列表'a'的函數的指針。
您也可以直接在循環中執行a.append(y)。