"string index out of range" error within quicksum
Awaiting user inputHello,
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
-
Official comment
This post is more than two years old. Some information may not be up to date. For current information, please check the Gurobi Documentation or Knowledge Base. If you need more help, please create a new post in the community forum, or try Gurobot, our chatbot interface offering instant, expert-level support. -
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
Post is closed for comments.
Comments
2 comments