title: Transform dictionary python
body: <p>I have a list of dictionaries in this form:</p>
  
  <pre><code>d_old=[{"color":"red","store":"1","s_d":{"M":"1","L":"2"}},       
         {"color":"blue","store":"2","s_d":{"S":"3","XL":"4"}}]
  </code></pre>
  
  <p>My goal is to transform this into:</p>
  
  <pre><code>d_new=[{"color":"red","store":"1","Size":"M", "Stock":"1"},
         {"color":"red","store":"1","Size":"L", "Stock":"2"},
         {"color":"blue","store":"2","Size":"S", "Stock":"3"},
         {"color":"blue","store":"2","Size":"XL", "Stock":"4"}]
  </code></pre>
  
  <p>I wrote this, it works but I like to know if there is a better way:
  The keys are always defined in a list, and here for simplification, only 2 keys are shown, there is more.</p>
  
  <pre><code>def transform_data(d_old):
      d_new_list =[]
      headers=["color","store"]
      for d in d_old:
          for key,value in d["s_d"].items():
              temp_dict = {header:d[header] for header in headers}
              temp_dict["Size"] = key
              temp_dict["Stock"] = value
              d_new_list.append(temp_dict)
  </code></pre>