• <bdo id='hfdvK'></bdo><ul id='hfdvK'></ul>
    1. <small id='hfdvK'></small><noframes id='hfdvK'>

    2. <i id='hfdvK'><tr id='hfdvK'><dt id='hfdvK'><q id='hfdvK'><span id='hfdvK'><b id='hfdvK'><form id='hfdvK'><ins id='hfdvK'></ins><ul id='hfdvK'></ul><sub id='hfdvK'></sub></form><legend id='hfdvK'></legend><bdo id='hfdvK'><pre id='hfdvK'><center id='hfdvK'></center></pre></bdo></b><th id='hfdvK'></th></span></q></dt></tr></i><div id='hfdvK'><tfoot id='hfdvK'></tfoot><dl id='hfdvK'><fieldset id='hfdvK'></fieldset></dl></div>

      1. <tfoot id='hfdvK'></tfoot>

        <legend id='hfdvK'><style id='hfdvK'><dir id='hfdvK'><q id='hfdvK'></q></dir></style></legend>

        排序()返回无

        sort() returns None(排序()返回无)
              <tbody id='ySjUH'></tbody>
              <bdo id='ySjUH'></bdo><ul id='ySjUH'></ul>
              <i id='ySjUH'><tr id='ySjUH'><dt id='ySjUH'><q id='ySjUH'><span id='ySjUH'><b id='ySjUH'><form id='ySjUH'><ins id='ySjUH'></ins><ul id='ySjUH'></ul><sub id='ySjUH'></sub></form><legend id='ySjUH'></legend><bdo id='ySjUH'><pre id='ySjUH'><center id='ySjUH'></center></pre></bdo></b><th id='ySjUH'></th></span></q></dt></tr></i><div id='ySjUH'><tfoot id='ySjUH'></tfoot><dl id='ySjUH'><fieldset id='ySjUH'></fieldset></dl></div>

            • <tfoot id='ySjUH'></tfoot>

                <small id='ySjUH'></small><noframes id='ySjUH'>

                <legend id='ySjUH'><style id='ySjUH'><dir id='ySjUH'><q id='ySjUH'></q></dir></style></legend>

                  本文介绍了排序()返回无的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  代码:

                  import math
                  import time
                  import random
                  class SortClass(object):
                      def sort1(self, l):
                          if len(l)==1:
                              return l
                          elif len(l)==2:
                              if l[0]<l[1]:
                                  return l
                              else:
                                  return l[::-1]
                          else:
                              pivot=math.floor(len(l)/2)
                              a=l[pivot:]
                              b=l[:pivot]
                              a2=self.sort1(a)
                              b2=self.sort1(b)
                              if a2==None or b2==None:
                                  a2=[]
                                  b2=[]
                              return (a2+b2).sort()
                          return []
                  Sort=SortClass()
                  x=[20,19,18,17,16,15,14,13,12,11,10,9,8,7,6,5,4,3,2,1]
                  print(Sort.sort1(x))
                  

                  代码输出 None 即使它在两种情况下应该返回一个空列表:

                  The code outputs None even though it should return an empty list in two cases:

                  return []
                  

                  a2=self.mergeSort(a)
                  b2=self.mergeSort(b)
                  if a2==None or b2==None:
                      a2=[]
                      b2=[]
                  return (a2+b2).sort()
                  

                  详情:该代码用于我为 python 练习制作的列表排序模块(我在 python 方面相对较新).sort1 是经过修改的归并排序.

                  Details: The code is for a list sorting module I am making for python practice (I am relatively new at python). sort1 is a modified mergesort.

                  推荐答案

                  @reut 先解决了,但是

                  @reut got to it first but

                  return sorted(a2+b2)
                  

                  不是

                  return (a2+b2).sort()
                  

                  另外

                  if a2 == None or b2 == None:
                      a2 = []
                      b2 = []
                  

                  应该是

                  if a2 == None:
                      a2 = []
                  if b2 == None:
                      b2 = []
                  

                  如果a2 为[1] 且b2 为none,则您将两者都设置为[] 如果a2 为[1] 且b2 为none,则您将a2 丢弃.我猜这是无意的.

                  Your setting both to [] if either is none meaning if a2 is [1] and b2 is none your throwing away a2. I'm guessing this is unintended.

                  在您的代码中,您在较低的 sortClass 中有一个大写的 S

                  Also in your code you have an uppercase S in the lower sortClass

                  此外返回[]永远不会回来,上面的else不允许它.

                  in addition return[] will never return, the above else does not allow it to.

                  这篇关于排序()返回无的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Initialize Multiple Numpy Arrays (Multiple Assignment) - Like MATLAB deal()(初始化多个 Numpy 数组(多重赋值) - 像 MATLAB deal())
                  How to extend Python class init(如何扩展 Python 类初始化)
                  What#39;s the difference between dict() and {}?(dict() 和 {} 有什么区别?)
                  What is a wrapper_descriptor, and why is Foo.__init__() one in this case?(什么是 wrapper_descriptor,为什么 Foo.__init__() 在这种情况下是其中之一?)
                  Initialize list with same bool value(使用相同的布尔值初始化列表)
                  setattr with kwargs, pythonic or not?(setattr 与 kwargs,pythonic 与否?)

                      <tbody id='GPzZr'></tbody>

                    1. <legend id='GPzZr'><style id='GPzZr'><dir id='GPzZr'><q id='GPzZr'></q></dir></style></legend>
                      <i id='GPzZr'><tr id='GPzZr'><dt id='GPzZr'><q id='GPzZr'><span id='GPzZr'><b id='GPzZr'><form id='GPzZr'><ins id='GPzZr'></ins><ul id='GPzZr'></ul><sub id='GPzZr'></sub></form><legend id='GPzZr'></legend><bdo id='GPzZr'><pre id='GPzZr'><center id='GPzZr'></center></pre></bdo></b><th id='GPzZr'></th></span></q></dt></tr></i><div id='GPzZr'><tfoot id='GPzZr'></tfoot><dl id='GPzZr'><fieldset id='GPzZr'></fieldset></dl></div>
                      <tfoot id='GPzZr'></tfoot>

                      <small id='GPzZr'></small><noframes id='GPzZr'>

                          <bdo id='GPzZr'></bdo><ul id='GPzZr'></ul>