def _get_level_lengths(index, hidden_elements=None):
    '\n    Given an index, find the level length for each element.\n\n    Optional argument is a list of index positions which\n    should not be visible.\n\n    Result is a dictionary of (level, inital_position): span\n    '
    sentinel = object()
    levels = index.format(sparsify=sentinel, adjoin=False, names=False)
    if (hidden_elements is None):
        hidden_elements = []
    lengths = {}
    if (index.nlevels == 1):
        for (i, value) in enumerate(levels):
            if (i not in hidden_elements):
                lengths[(0, i)] = 1
        return lengths
    for (i, lvl) in enumerate(levels):
        for (j, row) in enumerate(lvl):
            if (not get_option('display.multi_sparse')):
                lengths[(i, j)] = 1
            elif ((row != sentinel) and (j not in hidden_elements)):
                last_label = j
                lengths[(i, last_label)] = 1
            elif (row != sentinel):
                last_label = j
                lengths[(i, last_label)] = 0
            elif (j not in hidden_elements):
                lengths[(i, last_label)] += 1
    non_zero_lengths = {element: length for (element, length) in lengths.items() if (length >= 1)}
    return non_zero_lengths
Given an index, find the level length for each element.

Optional argument is a list of index positions which
should not be visible.

Result is a dictionary of (level, inital_position): span
def _get_level_lengths(index, hidden_elements=None):
    '\n    Given an index, find the level length for each element.\n\n    Optional argument is a list of index positions which\n    should not be visible.\n\n    Result is a dictionary of (level, inital_position): span\n    '
    sentinel = object()
    levels = index.format(sparsify=sentinel, adjoin=False, names=False)
    if (hidden_elements is None):
        hidden_elements = []
    lengths = {}
    if (index.nlevels == 1):
        for (i, value) in enumerate(levels):
            if (i not in hidden_elements):
                lengths[(0, i)] = 1
        return lengths
    for (i, lvl) in enumerate(levels):
        for (j, row) in enumerate(lvl):
            if (not get_option('display.multi_sparse')):
                lengths[(i, j)] = 1
            elif ((row != sentinel) and (j not in hidden_elements)):
                last_label = j
                lengths[(i, last_label)] = 1
            elif (row != sentinel):
                last_label = j
                lengths[(i, last_label)] = 0
            elif (j not in hidden_elements):
                lengths[(i, last_label)] += 1
    non_zero_lengths = {element: length for (element, length) in lengths.items() if (length >= 1)}
    return non_zero_lengths