我有一个类,其唯一目的是对作为参数给出的数组进行排序,但首先,我收到一个错误“int not iterable”。我的问题是这个错误是什么,我的排序是否正确?谢谢。这是我的分类器类被下面的另一个类调用。
class Sorter:
def reverseWackySort(self, vals):
i = 0
j = 0
temp = 0
length = len(vals)
for i in length:
for j in (length -1):
if vals[j] > vals[j+1]:
temp = vals[j]
vals[j] = vals[j+1]
vals[j+1] = temp;
return vals
代码 -
from Sorter import Sorter
def TestSorter():
rws = Sorter()
nums = [88, 1, 7, 32, 18, 77, 34, 99, 54, 22]
print "\nBefore Sort: ", nums
rws.reverseWackySort(nums)
print "After Sort: {}\n".format(nums)
TestSorter()