def apply_constraint(data, constraint_func):
    """
    Return a subset of data that satisfies constraint_function
    If constraint_func is None, return back entire data
    """

    if constraint_func is None:
        return data
    else:
        outdata = {}
        for key, val in data.items():
            if constraint_func(val):
                outdata[key] = val
    return outdata