def combine_cols(df, cols: list, sep='__', name='id', reverse=False):
    """Returns a copy of `df` with `cols` combined into a single coloumn `name`,
    separated by `sep`, or with the `name` column expanded into `cols` if `reverse` is True."""

    df = df.copy()
    if reverse:
        final_cols = cols + df.drop(name, axis=1).columns.tolist()
        df[cols] = df[name].str.split(sep).tolist()
    else:
        final_cols = [name] + df.drop(cols, axis=1).columns.tolist()
        df[name] = df[cols].astype(str).apply(sep.join, axis=1)
    return df[final_cols]