Need help with nested dictionary

I am trying to loop through a nested dictionary and print the key and value for every item in the dictionary. How may I achieve this?

Example Dictionary:

{'conversation_end': '2021-11-03T13:44:10.896000+00:00',
 'conversation_id': '560904d6-5997-4ae2-a234-gfgfgfgf',
 'conversation_initiator': None,
 'conversation_start': '2021-11-03T13:41:22.603000+00:00',
 'division_ids': ['7ef8bfd4-e12e-4310-90a1-fafg'],
 'evaluations': None,
 'external_tag': None,
 'knowledge_base_ids': None,
 'media_stats_min_conversation_mos': 4.872452259063721,
 'media_stats_min_conversation_r_factor': 92.01608276367188,
 'originating_direction': 'inbound',
 'participants': [{'external_contact_id': None,
                   'external_organization_id': None,
                   'flagged_reason': None,
                   'participant_id': 'c844a53c-70bf-441d-81ce-cccd572baf08',
                   'participant_name': '',
                   'purpose': 'customer',
                   'sessions': [{'active_skill_ids': None,
                                 'acw_skipped': None,
                                 'address_from': None,
                                 'address_other': None,
                                 'address_self': None,
                                 'address_to': None,
                                 'agent_assistant_id': None,
                                 'agent_bullseye_ring': None,
                                 'agent_owned': None,

My current code looks like this.

<table class="table table-bordered table-success">

{% for key, value in data.items %}
 <tr>
     <td> {{ key }} </td> 
     <td> {{ value }} </td>
 </tr>
 {% endfor %} {% endblock %}
 </table>

I do not want participants like the way it is below and want to continue displaying the key, value of every item in the dictionary as the items above participants.

Hi Chris,

It seems like you're using django templating. It would be best to consult the django docs on how to handle nested dictionaries.

Hi Ronan,

Thank you, would you know how I could do this using python by any chance?

Thank you.

Hi Chris,

No sorry, I'm not familiar with the Django framework.

I meant in regular python and not Django.

Kind Regards,
Chris Carr

Hi Chris,

Real Python is usually my source for solving python problems.
This tutorial on iterating through dictionaries should be of some help: How to Iterate Through a Dictionary in Python – Real Python

Thank you, looks like recursion is the way to go here. I will try it out and update the post.

This topic was automatically closed 31 days after the last reply. New replies are no longer allowed.