[Python] Iterating over dictionary of lists of dictionaries in python [closed]

Discussão em 'Python' iniciado por Stack, Março 15, 2025.

  1. Stack

    Stack Membro Participativo

    Please help in providing a solution to iterate through a dictionary containing lists of dictionaries in python. To be precise below is the structure you can consider for the dictionary:

    {
    "cart": [
    {
    "id": "0Zy2jwLzQzlk7xq3",
    "benefit_id": "-1",
    "plan_id": "-1",
    "change": 5,
    "change_at": "2025-03-13 15:03:00+05:30",
    "nominees": [],
    "dependents_ids": [],
    "upload_nominees_form": null,
    "mid_term": false,
    "endorsement_id": "OJ1xzPR8N2V0gMbd",
    "premium_value": 0.0,
    "sum_insured": 0,
    "annual_premium": 0.0,
    "employer_premium": 0.0,
    "added_by": 0
    },
    {
    "id": "J1xzPR8JmLV0gMbd",
    "benefit_id": "-1",
    "plan_id": "-1",
    "change": 4,
    "change_at": "2025-03-13 15:03:05+05:30",
    "nominees": [],
    "dependents_ids": [],
    "upload_nominees_form": null,
    "mid_term": false,
    "endorsement_id": "OJ1xzPR8N2V0gMbd",
    "premium_value": 0.0,
    "sum_insured": 0,
    "annual_premium": 0.0,
    "employer_premium": 0.0,
    "added_by": 0
    }],
    "complete_cart": [{"modified":"false"}]
    }


    I am using a for loop to iterate through the values, but is getting below error:

    TypeError: string indices must be integers, not 'str'


    I want to read the values of subkeys inside each list dictionary to apply further logics

    Continue reading...

Compartilhe esta Página