import textwrap


def compact_simple_list(match):
    """Callback function. Given a simple list match, compact it and ensure
    that it wraps around by 80 characters.

    Params:
        match The regular expression match

    Returns:
        The string to replace the expression with

    """
    # Calculate the initial indent as the length of the first match group
    initial_indent = len(match.group(1))

    # Get the lines in the match
    lines = match.group(2).splitlines()

    # Set the indent by finding the indent of the first lines
    if len(lines) > 1:
        subsequent_indent = len(lines[1]) - len(lines[1].lstrip())
    else:
        subsequent_indent = 0

    # Strip whitespace from the lines
    lines = [l.strip() for l in lines]

    # Create and return the string wrapped about 80 chars
    list_string = "\n".join(
        textwrap.wrap(
            " ".join(lines),
            80,
            initial_indent=" " * initial_indent,
            subsequent_indent=" " * subsequent_indent,
        )
    ).lstrip()

    # Return the string
    return match.group(1) + list_string