メインコンテンツへスキップ

comparison of the values of two dictionnaries

回答済み

コメント

2件のコメント

  • 正式なコメント
    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 try Gurobot, our chatbot interface offering instant, expert-level support.
  • Jaromił Najman
    • Gurobi Staff

    Please note that this is not a Gurobi question but a general Python question and should be and should be rather posted in a Python forum instead of here.

    Anyway, you are overwriting your \(\texttt{dvar}\) values with \(0\). For example, when you check for \(\texttt{Order[1][4]}\) and \(\texttt{Aisle_arct[1][0]}\), you will temporarily have a value of \(\texttt{dvar[1,1]=L}\). However, the last comparison for \(\texttt{i=1, k=1}\) is  \(\texttt{Order[1][12]='d'}\) \(\neq\) \(\texttt{'g'=Aisle_arct[1][4]}\) and thus you get \(\texttt{dvar[1,1]=0}\).

    I don't know what you want to do with the \(\texttt{dvar}\) dict, but one way (probably not the most pythonic one) to get only the matching characters would be

    dvar={}
    for i in Order:
        for k in Aisle_arct:
            dvar[i,k] = []
            for z in Order[i]:
                for j in Aisle_arct[k]:
                    if (z==j):
                        dvar[i,k].append(z)

    print(dvar)

    Best regards, 
    Jaromił

    0

投稿コメントは受け付けていません。