"string index out of range" error within quicksum
ユーザーの入力を待っています。Hello,
The below line of code gives me an "IndexError: string index out of range" error:
for j in def_attributes:
m.addConstr(gp.quicksum(PlayerSelect[i]*current_fitness[i]*PlayerAttributes[i,j] for i in players if position[i] == 'Defender') >= attravg['Defender']*oppfit['Defender'], 'DefenderFitnessConstraint')
I've determined its at the 'position[i] == 'Defender'' part.
If i query the 'position' variable, i get an output. For example, print (position['name']) returns a string value with the position.
How do I avoid the index error? Is there a workaround?
Thanks,
Abhishek
0
-
Hi Abhishek,
Could you please post a minimal reproducible example? It is very hard to provide useful help with this little of information.
You could try to isolate the error by running a \(\texttt{for}\)-loop for the \(\texttt{position[i] == 'Defender' part only}\)
for i in players:
print(i)
print(position[i])
if position[i] == 'Defender':
print("In if-clause")and see what happens.
Best regards,
Jaromił0
サインインしてコメントを残してください。
コメント
1件のコメント