I tried to code and get the right fitness_point here but after the loop the result keep showing as 0. It first showing the StopIteration, so I write try and except there, but the result is still wrong.. I am a completely newbie here, what should I do? please help..
population={'list_1':[0,2,3,4],'list_2':[2,0,4,1],'list_3':[1,6,0,8],'list_4':[3,5,6,0]}
item = [3,4,2,1]
def get_fitness(items):
g= iter(items)
temp=[]
fitness_point=0
try:
for i in items:
if i != items[3]:
temp=population['list_{}'.format(i)]
fitness_point+=temp[g.__next__()-1]
print(fitness_point)
except GeneratorExit:
return 'eror'
return fitness_point
print(get_fitness(item))