def semiflatten(multi):
 if multi:
  result = multi.to_dict(flat=False)
  for (k, v) in result.items():
   if (len(v) == 1):
    result[k] = v[0]
  return result
 else:
  return multi

def semiflatten ( multi ) : if multi : result = multi . to_dict ( flat = False ) for ( k , v ) in result . items ( ) : if ( len ( v ) == 1 ) : result [ k ] = v [ 0 ] return result else : return multi
convert a mutidict into a regular dict .