def _reGroupDict(d, newgr):
 r = {}
 newgrks = newgr.keys()
 for (k, v) in d.items():
  if (k in newgrks):
   r.setdefault(newgr[k][0], {})[newgr[k][1]] = v
  else:
   r[k] = v
 return r

def _reGroupDict ( d , newgr ) : r = { } newgrks = newgr . keys ( ) for ( k , v ) in d . items ( ) : if ( k in newgrks ) : r . setdefault ( newgr [ k ] [ 0 ] , { } ) [ newgr [ k ] [ 1 ] ] = v else : r [ k ] = v return r
regroup keys in the d dictionary in subdictionaries .