def single_or(seq, default, cond=None):
    """Extract a single item from a sequence matching condition `cond`

    Returns `default` if no item is found.

    Raises IndexError if there is more than one item matching the condition.
    """
    if cond is None:
        cond = lambda x: True
    NOMATCH = object()
    result = NOMATCH
    for x in seq:
        if not cond(x):
            continue
        if result is not NOMATCH:
            raise IndexError('Multiple items found')
        result = x
    if result is NOMATCH:
        result = default
    return result
