def iterate(dataset, dims):
    """Iterate over all xarray dimensions except specified ones.

    Parameters
    ----------
    dataset : xarray Dataset
        Input dataset
    dims : sequence of strings
        Dimension to exclude from iteration

    Returns
    -------
    names : sequence of strings
        Names of coordinates that are being iterated.

    iterator : iterator over (key, par, val)
        key : sequence of values in the same order as returned by "names"
        val : subset of dataset corresponding to iteration
    """
    names = [p for p in list(dataset.dims) if p not in dims]
    stacked = dataset.stack(internal_iterator=names)
    stacked = stacked.transpose('internal_iterator', *dims)

    def iterator():
        for i, p in enumerate(stacked.internal_iterator):
            key = p.data.tolist()
            val = stacked.sel(internal_iterator=p).drop('internal_iterator')
            val = val.assign_coords(**dict(zip(names, key)))
            yield (key, val)

    return names, iterator()