def flatten_dict(dct, fields, *, rest_val=None, extras_action='raise',
                 field_set=None):
    """
    >>> flatten_dict({'a': 1, 'b': 2}, ('a', 'b'))
    [1, 2]

    >>> flatten_dict({'a': 1, 'b': 2}, ('a', 'b', 'c'))
    Traceback (most recent call last):
        ...
    KeyError: 'c'

    >>> flatten_dict({'a': 1, 'b': 2}, ('a', 'b', 'c'), rest_val=5)
    [1, 2, 5]

    >>> flatten_dict({'a': 1, 'b': 2, 'c': 5}, ('a', 'b'))
    Traceback (most recent call last):
        ...
    ValueError: ('invalid extra keys', {'c'})

    >>> flatten_dict({'a': 1, 'b': 2, 'c': 5}, ('a', 'b'),
    ...              extras_action='ignore')
    [1, 2]
    """
    if extras_action == 'raise':
        extras = dct.keys() - (field_set or set(fields))
        if extras:
            raise ValueError('invalid extra keys', extras)
    if rest_val is not None:
        return [dct.get(f, rest_val) for f in fields]
    return [dct[f] for f in fields]