check if the current element is equal to previous element .
if ( ele [ idx - 1 ] == ele [ idx ] ) : NEW_LINE INDENT freq += 1 NEW_LINE idx += 1 NEW_LINE DEDENT else : NEW_LINE INDENT print ( element , " ▁ " , freq ) ; NEW_LINE element = ele [ idx ] NEW_LINE idx += 1 NEW_LINE DEDENT