0

I'm not able to convert two list to json format.

i have tried to convert two list to dictionary format and then converted to json format but duplicate key arenot there which i want too.

    p = np.argmax(y[:416], axis=-1)
    # print(p)
    flat_list_te = padd_to_2d_senti[:416]
    flat_list_test = [item for sublist in flat_list_te for item in sublist]
    # print(flat_list_test)
    # flat_list = [item for sublist in y_te[i] for item in sublist]
    flat_list_pred = [item for sublist in p for item in sublist]
    key = []
    value = []
    for w,pred in zip(flat_list_test,flat_list_pred):
        predicted_tag = idx2tag[pred]

        if predicted_tag !='O':
            a.append(w)
            b.append(idx2tag[pred])
    test_pred = dict(zip(key,value))
expected output:
    key = ["phone","age","class","class"]
    value = [123,4,5,6]
    dic = {"phone":123,"age":4,"class":5,"class":6}
Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
Suraj Ghale
  • 173
  • 1
  • 5
  • 13

1 Answers1

2

Each key within a dict needs to be unique. So this dictionary is not possible:

dic = {"phone":123,"age":4,"class":5,"class":6}

"class" exists twice.

Possible solutions:

  • rename one of the "class"strings to something unique
  • create a tuple for the value of key "class", e.g. dic = {"class":(5, 6)}
fluxens
  • 565
  • 3
  • 15