from pathlib import Path


def load_groups(input_path: Path) -> list:
    """
    Load in the customs quesetionarre response data into a buffer and group
    together the responses that are associated with a single group.
    Responses belonging to a single group are on contiguous lines,
    and groups are separated by a blank line. Splitting by "\n\n" will
    break apart the responses from separate groups, and then removing
    the "\n" characters from in-group responses should then just give
    us the specific responses void of whitespace characters.

    Remove empty characters per line and also empty groups.

    Args:
        input_path [pathlib.Path]: path to input data

    Returns:
        list of lists: [ [group-responses] ]
    """
    with open(input_path, "r") as infile:
        groups = list(
            filter(
                None,
                [
                    list(
                        filter(
                            None,
                            [line.strip() for line in group.split("\n") if line != ""],
                        )
                    )
                    for group in infile.read().split("\n\n")
                ],
            )
        )
        return groups