Get path of all the elements in dictionary
<p>I have a dictionary in python and want to get path of values param1 or param2, ... to replace these with some other values.  Say to get the value of param1 I need to get it like ['OptionSettings'][2]['Value']. Can I have some generic code to do this, which will print the path of all my nodes/leaves 
below is the dictionary</p>

<pre><code>{
        "ApplicationName": "Test",
        "EnvironmentName": "ABC-Nodejs",
        "CNAMEPrefix": "ABC-Neptune",
        "SolutionStackName": "64bit Amazon Linux 2016.03 v2.1.1 running Node.js",
        "OptionSettings": [
                           {
                            "Namespace": "aws:ec2:vpc",
                            "OptionName": "AssociatePublicIpAddress",
                            "Value": "true"
                            },
                           {
                            "Namespace": "aws:elasticbeanstalk:environment",
                            "OptionName": "EnvironmentType",
                            "Value": "LoadBalanced"
                            },
                           {
                            "Namespace": "aws:ec2:vpc",
                            "OptionName": "Subnets",
                            "Value": "param1"
                            },
                           {
                            "Namespace": "aws:autoscaling:launchconfiguration",
                            "OptionName": "SecurityGroups",
                            "Value": "param2"
                            },
                           {
                            "Namespace": "aws:autoscaling:asg",
                            "OptionName": "MinSize",
                            "Value": "1"
                            },
                           {
                            "Namespace": "aws:autoscaling:asg",
                            "OptionName": "MaxSize",
                            "Value": "4"
                            },
                           {
                            "Namespace": "aws:autoscaling:asg",
                            "OptionName": "Availability Zones",
                            "Value": "Any"
                            },
                           {
                            "Namespace": "aws:autoscaling:asg",
                            "OptionName": "Cooldown",
                            "Value": "360"
                            },
                           {
                            "Namespace": "aws:autoscaling:launchconfiguration",
                            "OptionName": "IamInstanceProfile",
                            "Value": "NepRole"
                            },
                           {
                            "Namespace": "aws:autoscaling:launchconfiguration",
                            "OptionName": "MonitoringInterval",
                            "Value": "5 minutes"
                            },
                           {
                            "Namespace": "aws:autoscaling:launchconfiguration",
                            "OptionName": "RootVolumeType",
                            "Value": "gp2"
                            },
                           {
                            "Namespace": "aws:autoscaling:launchconfiguration",
                            "OptionName": "RootVolumeSize",
                            "Value": "10"
                            },
                           {
                            "Namespace": "aws:elasticbeanstalk:sns:topics",
                            "OptionName": "Notification Endpoint",
                            "Value": "sunil.kumar2@pb.com"
                            },
                           {
                            "Namespace": "aws:elasticbeanstalk:hostmanager",
                            "OptionName": "LogPublicationControl",
                            "Value": "false"
                            },
                           {
                            "Namespace": "aws:elasticbeanstalk:command",
                            "OptionName": "DeploymentPolicy",
                            "Value": "Rolling"
                            },
                           {
                            "Namespace": "aws:elasticbeanstalk:command",
                            "OptionName": "BatchSizeType",
                            "Value": "Percentage"
                            },
                           {
                            "Namespace": "aws:elasticbeanstalk:command",
                            "OptionName": "BatchSize",
                            "Value": "100"
                            },
                           {
                            "Namespace": "aws:elasticbeanstalk:command",
                            "OptionName": "HealthCheckSuccessThreshold",
                            "Value": "Ok"
                            },
                           {
                            "Namespace": "aws:elasticbeanstalk:command",
                            "OptionName": "IgnoreHealthCheck",
                            "Value": "false"
                            },
                           {
                            "Namespace": "aws:elasticbeanstalk:command",
                            "OptionName": "Timeout",
                            "Value": "600"
                            },
                           {
                            "Namespace": "aws:autoscaling:updatepolicy:rollingupdate",
                            "OptionName": "RollingUpdateEnabled",
                            "Value": "false"
                            },
                           {
                            "Namespace": "aws:ec2:vpc",
                            "OptionName": "ELBSubnets",
                            "Value": "param3"
                            },
                           {
                            "Namespace": "aws:elb:loadbalancer",
                            "OptionName": "SecurityGroups",
                            "Value": "param4"
                            },
                           {
                            "Namespace": "aws:elb:loadbalancer",
                            "OptionName": "ManagedSecurityGroup",
                            "Value": "param4"
                            }
                           ]

}
</code></pre>

<p>This is essentially the same question as this:</p>

<p><a href="http://stackoverflow.com/questions/34836777/print-complete-key-path-for-all-the-values-of-a-python-nested-dictionary">Print complete key path for all the values of a python nested dictionary</a></p>

<p>It is essentially the necessary code. What you are going to need to add is the handling of the lists, since you are not presenting simply a key/value structure, and that can be addressed by this question here:</p>

<p><a href="http://stackoverflow.com/questions/25231989/how-to-check-if-a-variable-is-a-dictionary-in-python">How to check if a variable is a dictionary in python</a></p>

<p>Which will show you how to check for a type and modify behavior based on the data type. The easiest way to accomplish this is to set up two dummy data types, one defined as an empty list and the other as an empty map and perform "isinstance" checks of the elements against the dummy types to decide on what logic you will want to execute.</p>

<p>Between the two of those answers, you should be able to build the paths you are looking for.</p>

<p><a href="http://stackoverflow.com/users/4777872/lost">Lost</a> is right, this is not a "write it for me" site.</p>

python python-2.7 python-3.x dictionary boto3