def sectionize(parts, first_is_heading=False):
    """Join parts of the text after splitting into sections with headings.

    This function assumes that a text was splitted at section headings,
    so every two list elements after the first one is a heading-section pair.
    This assumption is used to join sections with their corresponding headings.

    Parameters
    ----------
    parts : list of str
        List of text parts.
    first_is_heading : bool
        Should first element be treated as heading in lists of length greater than 1.
    """
    parts = parts.copy()
    if len(parts) <= 1:
        return parts
    first = []
    if not first_is_heading:
        first.append(parts[0])
        del parts[0]
    sections = first + [ "\n".join(parts[i:i+2]) for i in range(0, len(parts), 2) ]
    return sections