Python-Dictionary parsing and update better
<p>I have an input dictionary which looks like this:</p>

<pre><code>{"payment": 
    {"payment_id": "AAHPW34190", "clm_list": 
        {"dtl": 
            [{"clm_id": "1A2345"},
             {"clm_id": "9999"}
            ]},
         "payment_amt": "20"}}
</code></pre>

<p>I need the output to look like this:</p>

<pre><code>{ "create":  
    { "_index": "website", "_type": "blog", "_id": "AAHPW34190"}}
{"payment_id": "AAHPW34190", "clm_list": 
    {"dtl": 
        [{"clm_id": "1A2345"},
         {"clm_id": "9999"}
        ]},
     "payment_amt": "20"}
</code></pre>

<p>The value of _id in the first line of output is derived from payment_id.
I can get the above output easily, by doing the following:</p>

<pre><code>static_line={ "create":  { "_index": "website", "_type": "blog", "_id": "0"}}
orig={"payment": {"payment_id": "AAHPW34190", "clm_list": {"dtl": [{"clm_id": "1A2345"}, {"clm_id": "9999"}]}, "payment_amt": "20"}}`
sec_line=orig["payment"]
static_line["_id"]=sec_line["payment_id"]`
</code></pre>

<p>But my input is going to be a million dict elements, and I want to do it as efficiently as possible.
So can I do it better for a million dicts?</p>

<p>I reformat the output of your input dict. suppose that the following dict is an element of a list, in which there are millions of dict.</p>

<pre><code>{"payment": {"payment_id": "AAHPW34190",
               "clm_list": {"dtl": [{"clm_id": "1A2345"}, {"clm_id":"9999"}]},
            "payment_amt": "20"}
}
</code></pre>

<p>use a list comprehension to extract the payment_id and create new dict</p>

<pre><code>[{ "create":  { "_index": "website", "_type": "blog", "_id": d['payment']['payment_id']}} 
for d in my_list_of_dict]
</code></pre>

python dictionary