def get_attribute_checker(operator, attribute, value=''):
    """
    Takes an operator, attribute and optional value; returns a function that
    will return True for elements that match that combination.
    """
    return {'=': lambda el: el.get(attribute) == value, '~': lambda el: 
        value in el.get(attribute, '').split(), '^': lambda el: el.get(
        attribute, '').startswith(value), '$': lambda el: el.get(attribute,
        '').endswith(value), '*': lambda el: value in el.get(attribute, ''),
        '|': lambda el: el.get(attribute, '') == value or el.get(attribute,
        '').startswith('%s-' % value)}.get(operator, lambda el: el.has_attr
        (attribute))
