code: def ensure_dim(core, dim, dim_):
      
      if dim is None:
          dim = dim_
      if not dim:
          return core, 1
      if dim_ == dim:
          return core, int(dim)
  
      if dim > dim_:
          key_convert = lambda vari: vari[:dim_]
      else:
          key_convert = lambda vari: vari + (0,)*(dim-dim_)
  
      new_core = {}
      for key, val in core.items():
          key_ = key_convert(key)
          if key_ in new_core:
              new_core[key_] += val
          else:
              new_core[key_] = val
  
      return new_core, int(dim)
docs: Ensure that dim is correct.