I am trying to sort a list by the class attribute of 'score' as the in built python sorted function seems to turn all other attributes of the object to "None". I have tried making a function to do this manually but when I run it the list inputted decreases in size as does the returned list, as well as the fact that the list becomes the same object repeated. The initial list is generated as follows:
para = []
class Parameters():
att1 = random.randint(5,125)
att2 = random.randint(5,125)
att3 = random.randint(30,360)
aa4 = random.randint(2,24)
score = random.randint(0,100)
for i in range(0,19):
para.append(Parameters())
Then my attempt at a sorting function is:
def sortPar(slist):
sortlist = []
sortlist = slist
x = []
val = 0
minval = 1000000
for item1 in slist:
minval = 10000000
for item in sortlist:
if item.score < minval:
print(item.score)
minval=item.score
val=item
x.append(val)
sortlist.remove(val)
return x
What is going wrong within the code and is there any other way I can do this? Thanks for the help.