def avgInDict(L):
  ''' Given a list L:
     [ {'S': [s11,s12,s13], 'V':[v11,v12,v13], ...},
       {'S': [s21,s22,s23], 'V':[v21,v22,v23], ...},
       {'S': [s31,s32,s33], 'V':[v31,v32,v33], ...},
       ... ]
       
     Return a dict:
     {'S': [s1,s2,s3], 'V':[v1,v2,v3], ...}

     where s1 = avg of (s11 + s21 + s31 + ...)
           s2 = avg of (s12 + s22 + s32 + ...)
  '''  
  ''' First turn L into:
      {'S': [ [s11,s12,s13],[s21,s22,s23],[s31,s32,s33], ...],
       'V': [ [v11,v12,v13],[v21,v22,v23],[v31,v32,v33], ...],
       ... }  '''

  keys = L[0].keys()
  new={}
  for k in keys:
      new[k] = []   # Init 'S':[]
      for x in L:   # x = {'S': [s11,s12,s13], 'V':[v11,v12,v13], ...}
          y = x[k]  # y = [s11,s12,s13]
          new[k].append(y) 

      ''' new[k] = [ [s11,s12,s13],[s21,s22,s23],[s31,s32,s33], ...]
          Then use avgInList=> {'S': [s1,s2,s3],'V': [v1,v2,v3],... }'''
      new[k] = avgInList(new[k])
  return new
 Given a list L:
     [ {'S': [s11,s12,s13], 'V':[v11,v12,v13], ...},
       {'S': [s21,s22,s23], 'V':[v21,v22,v23], ...},
       {'S': [s31,s32,s33], 'V':[v31,v32,v33], ...},
       ... ]
       
     Return a dict:
     {'S': [s1,s2,s3], 'V':[v1,v2,v3], ...}

     where s1 = avg of (s11 + s21 + s31 + ...)
           s2 = avg of (s12 + s22 + s32 + ...)
  
recipes/Python/278259_Dictionary_Tools/recipe-278259.py