我有一个.py文件,它接受一个列表,找到最小的数字,将它放入一个新的数组,从第一个数组中删除最小的数字,并重复,直到原始数组返回不包含更多的项目:
def qSort(lsort):
listlength = len(lsort)
sortedlist = list()
if listlength == 0:
return lsort
else:
while listlength > 0:
lmin = min(lsort)
sortedlist.append(lmin)
lsort.remove(lmin)
listlength = len(lsort)
return sortedlist
Run Code Online (Sandbox Code Playgroud)
现在另一个.py文件导入qSort并在某个列表上运行它,将其保存到变量.然后我尝试使用.reverse()列表上的命令,我最终得到它作为一个NoneType.我尝试使用reversed(),但它只是说"<listreverseiterator object at 0xSomeRandomHex>":
from qSort import qSort #refer to my first Pastebin
qSort = qSort([5,42,66,1,24,5234,62])
print qSort #this prints the sorted list
print type(qSort) #this prints <type 'list'>
print qSort.reverse() #this prints None
print reversed(qSort) …Run Code Online (Sandbox Code Playgroud)