import inspect


def extract_keys(function, kwargs, remove_from_orignal=True):
    """
    Function which extract the keys of "function" from "kwargs" by inspecting the signature of "function".

    """

    signature = inspect.signature(function)
    function_keys = signature.parameters.keys()

    if remove_from_orignal:
        kwargs_fn = {k: kwargs.pop(k) for k in function_keys if k in kwargs}
    else:
        kwargs_fn = {k: kwargs[k] for k in function_keys if k in kwargs}

    return kwargs_fn