def _filter_by_attr(list_in, attr_name, attr_val, match_substring=False):
    """
    Filter input list by the value of its elements' attributes.
    """
    list_out = []
    for val in list_in:
        if match_substring:
            if attr_val in getattr(val, attr_name):
                list_out.append(val)
        elif getattr(val, attr_name) == attr_val:
            list_out.append(val)
    return list_out
