Returns groups of elements from iterable,
    slicing just before predicate(elem) is True

def slice_before(predicate, iterable):
    """Returns groups of elements from iterable,
    slicing just before predicate(elem) is True
    """
    if isinstance(predicate, string_type):
        predicate = re.compile(predicate)

    if hasattr(predicate, 'match'):
        predicate = predicate.match

    record = []

    for i, item in enumerate(iterable):
        if i == 0:
            record = [item]
            continue

        if predicate(item):
            yield tuple(record)
            record = [item]
        else:
            record.append(item)

    if record:
        yield tuple(record)