def miscs_update_idxs_vals(miscs, idxs, vals, assert_all_vals_used=True, idxs_map=None):
 if (idxs_map is None):
  idxs_map = {}
 assert (set(idxs.keys()) == set(vals.keys()))
 misc_by_id = dict([(m['tid'], m) for m in miscs])
 for m in miscs:
  m['idxs'] = dict([(key, []) for key in idxs])
  m['vals'] = dict([(key, []) for key in idxs])
 for key in idxs:
  assert (len(idxs[key]) == len(vals[key]))
  for (tid, val) in zip(idxs[key], vals[key]):
   tid = idxs_map.get(tid, tid)
   if (assert_all_vals_used or (tid in misc_by_id)):
    misc_by_id[tid]['idxs'][key] = [tid]
    misc_by_id[tid]['vals'][key] = [val]
 return miscs

def miscs_update_idxs_vals ( miscs , idxs , vals , assert_all_vals_used = True , idxs_map = None ) : if ( idxs_map is None ) : idxs_map = { } assert ( set ( idxs . keys ( ) ) == set ( vals . keys ( ) ) ) misc_by_id = dict ( [ ( m [ 'tid' ] , m ) for m in miscs ] ) for m in miscs : m [ 'idxs' ] = dict ( [ ( key , [ ] ) for key in idxs ] ) m [ 'vals' ] = dict ( [ ( key , [ ] ) for key in idxs ] ) for key in idxs : assert ( len ( idxs [ key ] ) == len ( vals [ key ] ) ) for ( tid , val ) in zip ( idxs [ key ] , vals [ key ] ) : tid = idxs_map . get ( tid , tid ) if ( assert_all_vals_used or ( tid in misc_by_id ) ) : misc_by_id [ tid ] [ 'idxs' ] [ key ] = [ tid ] misc_by_id [ tid ] [ 'vals' ] [ key ] = [ val ] return miscs
unpack the idxs-vals format into the list of dictionaries that is misc .