-4

Hope you can help me with this question:

master_dict = {"Item": {"last_data": {"S": {"id":2689,
                                            "type":"question",
                                            "number":12,
                                            "offset":12,
                                            "status":0,
                                            "options": [ {"id":8045, "option":"opcion1"},
                                                         {"id":8046, "option":"opcion2"},
                                                         {"id":8044, "option":"opcion3"}],
                                            "question":"question question question?",
                                            "ts":1576192609
                                            }
                                    }
                        }
                }

This is a dictionary of dictionaries. How can I do so that I only print the "question" chain?

1 Answers1

0

As you have a dictionary of dictionaries, accessing each dictionary value will give you another dictionary. You can then access the values from that dictionary in the same way. For your particular example, you can do the following:

>>> master_dict["Item"]["last_data"]["S"]["question"]
'question question question?'

If instead, you want to access all occurrences of a certain key in a nested dictionary, this question should help you.

CDJB
  • 14,043
  • 5
  • 29
  • 55