import re


def parse_swift_recon(recon_out):
    """Parse swift-recon output into list of lists grouped by the content of
    the delimited blocks.

    Args:
        recon_out (str): CLI output from the `swift-recon` command.

    Returns:
        list: List of lists grouped by the content of the delimited blocks

    Example output from `swift-recon --md5` to be parsed:
    ============================================================================
    --> Starting reconnaissance on 3 hosts (object)
    ============================================================================
    [2018-07-19 15:36:40] Checking ring md5sums
    3/3 hosts matched, 0 error[s] while checking hosts.
    ============================================================================
    [2018-07-19 15:36:40] Checking swift.conf md5sum
    3/3 hosts matched, 0 error[s] while checking hosts.
    ============================================================================
    """

    lines = recon_out.splitlines()
    delimiter_regex = re.compile(r'^={79}')
    collection = []

    delimiter_positions = [ind for ind, x in enumerate(lines)
                           if delimiter_regex.match(x)]

    for ind, delimiter_position in enumerate(delimiter_positions):
        if ind != len(delimiter_positions) - 1:  # Are in the last position?
            start = delimiter_position + 1
            end = delimiter_positions[ind + 1]
            collection.append(lines[start:end])
    return collection