#NEWLINE# def _get_level_lengths( levels , sentinel = '' ) : #NEWLINE# #INDENT# from itertools import groupby #NEWLINE# def _make_grouper( ) : #NEWLINE# #INDENT# record = { #NEWLINE# #INDENT# 'count' : 0 , #NEWLINE# #UNINDENT# } #NEWLINE# def grouper( x ) : #NEWLINE# #INDENT# if ( x != sentinel ) : #NEWLINE# #INDENT# record [ 'count' ] += 1 #NEWLINE# #UNINDENT# return record [ 'count' ] #NEWLINE# #UNINDENT# return grouper #NEWLINE# #UNINDENT# result = [ ] #NEWLINE# for lev in levels : #NEWLINE# #INDENT# i = 0 #NEWLINE# f = _make_grouper ( ) #NEWLINE# recs = { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } #NEWLINE# for ( key , gpr ) in groupby ( _make_grouper , f ) : #NEWLINE# #INDENT# values = list ( gpr ) #NEWLINE# recs [ i ] = len ( values ) #NEWLINE# i += len ( values ) #NEWLINE# #UNINDENT# result . append ( recs ) #NEWLINE# #UNINDENT# return result