title: Nested Dictionary using python
body: <p>I am trying to write nested type of dictionary in python. I am providing my input and expected output and my tried code.</p>
  
  <p>This is my input:</p>
  
  <pre><code>input = [['10', 'PS_S1U_X2_LP', 'permit', 'origin', 'igp', 'RM_S1U_X2_LP'],
  ['20', '', 'permit', '', '', 'RM_S1U_X2_LP'], 
  ['10', 'MPLS-LOOPBACK', 'permit', '', '', 'MPLS-LOOPBACK-RLFA'], 
  ]
  </code></pre>
  
  <p>And my desired output is:</p>
  
  <pre><code>output = 
  "route_policy_list": [
  {
            "policy_terms": [],
            "route_policy_statement": [
              {
                "entry": "10",
                "prefix_list": "PS_S1U_X2_LP",
                "action_statements": [
                  {
                    "action_value": "igp",
                    "action": "permit",
                    "action_statement": "origin"
                  }
                ]
              },
              {
                  "entry": "20",
                  "prefix_list": "",
                  "action_statements": [
                    {
                      "action_value": "",
                      "action": "permit",
                      "action_statement": ""
                    }
                  ]  
              }
            ],
            "name": "RM_S1U_X2_LP"
  },
  
  
          {
            "policy_terms": [],
            "route_policy_statement": [
              {
                "entry": "10",
                "prefix_list": "MPLS-LOOPBACK",
                "action_statements": [
                  {
                    "action_value": "",
                    "action": "permit",
                    "action_statement": ""
                  }
                ]
              }
            ],
            "name": "MPLS-LOOPBACK-RLFA"
          } 
  ]
  </code></pre>
  
  <p>And I have tried this code:</p>
  
  <pre><code>from collections import defaultdict
  
  res1 = defaultdict(list)
  for fsm1 in input:
      name1 = fsm1.pop()
      action = fsm1[2]
      action_statement = fsm1[3]
      action_value = fsm1[4]
      item1 = dict(zip(['entry','prefix_list'],fsm1))
      res1['action'] = action
      res1['action_statement'] = action_statement
      res1['action_value'] = action_value
      res1[name].append(item1)
  
  print(res1)
  </code></pre>
  
  <p>Please help me to get desired output as mentioned above as i am new to coding and struggling to write.</p>