I have a class that's sole purpose is to sort an array that's given as a parameter, however first of all, I'm getting an error "int not iterable." My question is what is this error and am I doing my sorting correctly? Thanks. Here is my sorter class being called by the other class below.
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
Code -
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()
Sorterinstance for? This isn't Java, where you have to make every function a method… More importantly, do you have any reason to believe the class is relevant to the problem? If not, given that explaining it takes up half your text, and the implementation causes anIndentationError, and it draws more attention than your actual problem… maybe it would be better to trim things down to an SSCCE.sortedorlist.sort?