import re


def parse_protein_peeling(peeling_res):
    """
    This function parses the output of Protein Peeling software.

    Args:
        peeling_res (str): Terminal's output of Protein Peeling 3 software.

    Returns:
        dictionary: keys are => "Number of PUs for each peeling level"
                                "Boundaries of each PU for a given peelling level"
    """
    peeling_dict = {"NB_PU": [], "PU_BOUNDS": []}
    res_line_regex = re.compile("^[^#].*$")
    for line in peeling_res:
        # Looking for lines not starting with "#"
        res_line_found = re.search(res_line_regex, line)
        if res_line_found:
            res_line = res_line_found.group(0).split()
            peeling_dict["NB_PU"].append(int(res_line[4]))
            pu_bounds = [(x, y) for x, y in zip(res_line[5::2], res_line[6::2])]
            # Sort the tuples in place
            pu_bounds.sort(key=lambda tup: int(tup[0]))
            peeling_dict["PU_BOUNDS"].append(pu_bounds)
    return peeling_dict