def closest_number(val, num_list):
    """
    Return closest element to val in num_list.
    Parameters
    ----------
    val: integer, float,
        value to find closest element from num_list.
    num_list: list,
        list from which to find the closest element.
    Returns
    -------
    A element of num_list.
    """
    return min(num_list, key=lambda x: abs(x-val))