Skip to main content

KeyError: 0 in Python

Answered

Comments

4 comments

  • Official comment
    Simranjit Kaur
    • Gurobi Staff
    This post is more than three 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 why not try our AI Gurobot?.
  • Jaromił Najman
    • Gurobi Staff

    Hi Hilda,

    Your Python code is not indented. Could you please edit the indentation in your code such that it is executable?

    Best regards,
    Jaromił

    0
  • Hilda
    • Gurobi-versary
    • First Question
    • First Comment

    updated, thank you! Jaromił Najman

    0
  • Jaromił Najman
    • Gurobi Staff

    Hi Hilda,

    In your code, the list \(\texttt{j}\) is empty. List \(\texttt{j}\) is filled through list \(\texttt{P}\) which is also empty. List \(\texttt{P}\) depends on list \(\texttt{to_process}\) which is empty as well. List \(\texttt{to_process}\) is computed by the \(\texttt{solve_knapsack}\) function. I guess you have to revise the \(\texttt{solve_knapsack}\) fucntion and check whether it is correct. Simple \(\texttt{print("")}\) statements should be enough to debug this problem.

    Additionally, please note that the code as given has nothing to do with Gurobi. One of the stackexchange forums should be better suited for debugging questions.

    Best regards,
    Jaromił

    0

Post is closed for comments.