def _get_level_lengths(index, hidden_elements=None):
sentinel = object()<EOL>levels = index.format(sparsify=sentinel, adjoin=False, names=False)<EOL>if hidden_elements is None:<EOL><INDENT>hidden_elements = []<EOL><DEDENT>lengths = {}<EOL>if index.nlevels == <NUM_LIT:1>:<EOL><INDENT>for i, value in enumerate(levels):<EOL><INDENT>if(i not in hidden_elements):<EOL><INDENT>lengths[(<NUM_LIT:0>, i)] = <NUM_LIT:1><EOL><DEDENT><DEDENT>return lengths<EOL><DEDENT>for i, lvl in enumerate(levels):<EOL><INDENT>for j, row in enumerate(lvl):<EOL><INDENT>if not get_option('<STR_LIT>'):<EOL><INDENT>lengths[(i, j)] = <NUM_LIT:1><EOL><DEDENT>elif (row != sentinel) and (j not in hidden_elements):<EOL><INDENT>last_label = j<EOL>lengths[(i, last_label)] = <NUM_LIT:1><EOL><DEDENT>elif (row != sentinel):<EOL><INDENT>last_label = j<EOL>lengths[(i, last_label)] = <NUM_LIT:0><EOL><DEDENT>elif(j not in hidden_elements):<EOL><INDENT>lengths[(i, last_label)] += <NUM_LIT:1><EOL><DEDENT><DEDENT><DEDENT>non_zero_lengths = {<EOL>element: length for element, length in lengths.items() if length >= <NUM_LIT:1>}<EOL>return non_zero_lengths<EOL>
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