from typing import OrderedDict


def bs3_inverse_cols(sizes, *, offset=False, grid=12):
    """
    Convert a BS3 column sizes dict into a css class string,
    but calculate the inverse used for the labels on the left.

    The `sizes` may be a list of tuples instead of a dict.

    The `offset` argument is useful when a label is not present,
    and space needs to be padded.

    Set `grid` for a non-standard number of grid columns.

        >>> bs3_inverse_cols({'md': '6', 'xs': '8'})
        'col-md-6 col-xs-4'

        >>> bs3_inverse_cols({'md': '6', 'xs': '8'}, offset=True)
        'col-md-offset-6 col-xs-offset-4'

        >>> bs3_inverse_cols({'md': '6', 'xs': '8'}, grid=16)
        'col-md-10 col-xs-8'
    """
    if not isinstance(sizes, dict):
        sizes = OrderedDict(sizes)

    fmt = 'col-{k}-{v}' if not offset else 'col-{k}-offset-{v}'

    return ' '.join([
        fmt.format(k=k, v=grid - int(v))
        for k, v in sizes.items()
    ])