def restore_nesting(d, separator=':'):
 d = (copy.copy(d) if any([(separator in k) for k in d.keys()]) else d)
 for (k, v) in d.copy().items():
  if (separator in k):
   (top, rem) = k.split(separator, 1)
   nest = (d[top] if isinstance(d.get(top), dict) else {})
   nest[rem] = v
   d[top] = restore_nesting(nest, separator)
   del d[k]
 return d

def restore_nesting ( d , separator = ':' ) : d = ( copy . copy ( d ) if any ( [ ( separator in k ) for k in d . keys ( ) ] ) else d ) for ( k , v ) in d . copy ( ) . items ( ) : if ( separator in k ) : ( top , rem ) = k . split ( separator , 1 ) nest = ( d [ top ] if isinstance ( d . get ( top ) , dict ) else { } ) nest [ rem ] = v d [ top ] = restore_nesting ( nest , separator ) del d [ k ] return d
unwinds a flattened dict to restore nesting .