Iterate python dictionary to assign value to table's fields
Question: Using an API I get a json dictionary as response in the form:

    
    
    {"transacDet":[{"field1":6933434802,"field2":323499903,"field3":293483842},
    {"field1":693433448,"field2":333400300,"field3":298334300}],"responseStatus"
    :{"statusMessage":"success","statusCode":0}}
    

I am looking to create records in a table having the same corresponding fields
as in the json response: field1, field2, field3.

From the above example I would have 2 records:

    
    
    field1 = 6933434802
    field2 = 333400298
    field3 = 298334842
    

and then:

    
    
    field1 = 693433448
    field2 = 333400300
    field3 = 298334300
    

I have to iterate the response but not clear how.

I try using:

    
    
    for k in resp_json.items()[0][1][0]:
    print k
    

but I'm stuck there. TIA


Answer: 
    a= {"transacDet":[{"field1":6933434802,"field2":323499903,"field3":293483842},
    {"field1":693433448,"field2":333400300,"field3":298334300}],"responseStatus"
    :{"statusMessage":"success","statusCode":0}}
    
    import pandas as pd
    
    df =pd.DataFrame(a['transacDet'])
    
    df
    Out[11]: 
           field1     field2     field3
    0  6933434802  323499903  293483842
    1   693433448  333400300  298334300
    

iterate the dataframe:

    
    
    for i in df.iterrows(): print i[1], '\n'
    field1    6933434802
    field2     323499903
    field3     293483842
    Name: 0, dtype: int64 
    
    field1    693433448
    field2    333400300
    field3    298334300
    Name: 1, dtype: int64 
    

So if you don't want use `pandas`. just use generator (list comprehension),
this is based on @Dilettant 's solution:

    
    
    [(k, d[k]) for d in resp_json['transacDet'] for k in sorted(d.keys())]
    Out[24]: 
    [(u'field1', 6933434802L),
     (u'field2', 323499903),
     (u'field3', 293483842),
     (u'field1', 693433448),
     (u'field2', 333400300),
     (u'field3', 298334300)]
    

