signature:
def insert_many ( ol , eles , locs , ** kwargs ) :
    '''from elist . elist import *
 ol = [ 1,2,3,4,5]
 eles = [ 7,77,777]
 locs = [ 0,2,4]
 id ( ol )
 new = insert _ many ( ol , eles , locs )
 ol
 new
 id ( new )
 ol = [ 1,2,3,4,5]
 eles = [ 7,77,777]
 locs = [ 0,2,4]
 id ( ol )
 rslt = insert _ many ( ol , eles , locs , mode = " original " )
 ol
 rslt
 id ( rslt )'''

implementation:
if ( 'mode' in kwargs ) :
    mode = kwargs [ "mode" ]
else :
    mode = "new"
eles = copy . deepcopy ( eles )
locs = copy . deepcopy ( locs )
new = [ ]
length = ol . __len__ ( )
cpol = copy . deepcopy ( ol )
for i in range ( 0 , locs . __len__ ( ) ) :
    if ( locs [ i ] >= length ) :
        pass
    else :
        locs [ i ] = uniform_index ( locs [ i ] , length )
tmp = sorted_refer_to ( eles , locs )
eles = tmp [ 'list' ]
locs = tmp [ 'referer' ]
label = eles . __len__ ( )
si = 0
ei = 0
for i in range ( 0 , locs . __len__ ( ) ) :
    if ( locs [ i ] >= length ) :
        label = i
        break
    else :
        ei = locs [ i ]
        new . extend ( cpol [ si : ei ] )
        new . append ( eles [ i ] )
        si = ei
for i in range ( label , locs . __len__ ( ) ) :
    new . append ( eles [ i ] )
new . extend ( cpol [ ei : ] )
if ( mode == "new" ) :
    return ( new )
else :
    ol . clear ( )
    ol . extend ( new )
    return ( ol )


signature:
def insert_sections_some ( ol , * secs , ** kwargs ) :
    '''ol = initRange ( 0,20,1)
 ol
 loc = 6
 rslt = insert _ sections _ some ( ol , [ ' a ' , ' a ' , ' a ' ] , [ ' c ' , ' c ' , ' c ' , ' c ' ] , index = loc )
 rslt'''

implementation:
if ( 'mode' in kwargs ) :
    mode = kwargs [ "mode" ]
else :
    mode = "new"
loc = kwargs [ 'index' ]
secs = list ( secs )
secs = [ concat ( * secs ) ]
locs = [ loc ]
return ( insert_sections_many ( ol , secs , locs , mode = mode ) )


signature:
def insert_section ( ol , sec , loc , ** kwargs ) :
    '''ol = initRange ( 0,20,1)
 ol
 loc = 6
 sec = [ ' a ' , ' b ' , ' c ' , ' d ' ]
 rslt = insert _ section ( ol , sec , loc )
 rslt'''

implementation:
if ( 'mode' in kwargs ) :
    mode = kwargs [ "mode" ]
else :
    mode = "new"
secs = [ sec ]
locs = [ loc ]
return ( insert_sections_many ( ol , secs , locs , mode = mode ) )


implementation:
if ( 'mode' in kwargs ) :
    mode = kwargs [ "mode" ]
else :
    mode = "new"
secs = copy . deepcopy ( secs )
locs = copy . deepcopy ( locs )
brked = broken_seqs ( ol , locs )
seclen = secs . __len__ ( )
brklen = brked . __len__ ( )
if ( locs [ 0 ] == 0 ) :
    new = secs [ 0 ]
    length = seclen - 1
    if ( length < brklen ) :
        for i in range ( 0 , length ) :
            new . extend ( brked [ i ] )
            new . extend ( secs [ i + 1 ] )
        for i in range ( length , brklen ) :
            new . extend ( brked [ i ] )
    elif ( length == brklen ) :
        for i in range ( 0 , length ) :
            new . extend ( brked [ i ] )
            new . extend ( secs [ i + 1 ] )
    else :
        for i in range ( 0 , brklen ) :
            new . extend ( brked [ i ] )
            new . extend ( secs [ i + 1 ] )
        for i in range ( brklen , length ) :
            new . extend ( secs [ i ] )
else :
    new = brked [ 0 ]
    length = brklen - 1
    if ( length < seclen ) :
        for i in range ( 0 , length ) :
            new . extend ( secs [ i ] )
            new . extend ( brked [ i + 1 ] )
        for i in range ( length , seclen ) :
            new . extend ( secs [ i ] )
    elif ( length == seclen ) :
        for i in range ( 0 , length ) :
            new . extend ( secs [ i ] )
            new . extend ( brked [ i + 1 ] )
    else :
        for i in range ( 0 , seclen ) :
            new . extend ( secs [ i ] )
            new . extend ( brked [ i + 1 ] )
        for i in range ( seclen , length ) :
            new . extend ( brked [ i ] )
if ( mode == "new" ) :
    return ( new )
else :
    ol . clear ( )
    ol . extend ( new )
    return ( ol )


signature:
def reorder_sub ( ol , sub ) :
    '''sub = [ ' query ' , ' params ' , ' fragment ' , ' path ' ]
 ol = [ ' scheme ' , ' username ' , ' password ' , ' hostname ' , ' port ' , ' path ' , ' params ' , ' query ' , ' fragment ' ]
 reorder _ sub ( ol , sub )'''

implementation:
def cond_func ( ele , ol ) :
    index = ol . index ( ele )
    return ( index )
indexes = array_map ( sub , cond_func , ol )
nsub = sorted_refer_to ( sub , indexes ) [ 'list' ]
return ( nsub )


signature:
def sort ( ol , ** kwargs ) :
    '''from elist . elist import *
 ol = [ 1,3,4,2]
 id ( ol )
 new = sort ( ol )
 ol
 new
 id ( ol )
 id ( new )
 ol = [ 1,3,4,2]
 id ( ol )
 rslt = sort ( ol , mode = " original " )
 ol
 rslt
 id ( ol )
 id ( rslt )'''

implementation:
if ( 'mode' in kwargs ) :
    mode = kwargs [ "mode" ]
else :
    mode = "new"
if ( mode == "new" ) :
    new = copy . deepcopy ( ol )
    new . sort ( )
    return ( new )
else :
    ol . sort ( )
    return ( ol )


signature:
def sorted_refer_to ( l , referer , reverse = False , ** kwargs ) :
    '''from elist . elist import *
 l = [ " a " , " b " , " c " ]
 referer = [ 7,8,6]
 sorted _ refer _ to ( l , referer )
 { ' list ' : [ ' c ' , ' a ' , ' b ' ] , ' referer ' : [ 6 , 7 , 8 ] }
 referer'''

implementation:
if ( "mode" in kwargs ) :
    mode = kwargs [ "mode" ]
else :
    mode = "both"
tl = [ ]
length = l . __len__ ( )
for i in range ( 0 , length ) :
    ele = ( l [ i ] , referer [ i ] )
    tl . append ( ele )
tl = sorted ( tl , key = itemgetter ( 1 ) , reverse = reverse )
sorted_l = [ ]
sorted_r = [ ]
for i in range ( 0 , length ) :
    sorted_l . append ( tl [ i ] [ 0 ] )
    sorted_r . append ( tl [ i ] [ 1 ] )
if ( mode == "only-list" ) :
    return ( sorted_l )
elif ( mode == "only-referer" ) :
    return ( referer )
else :
    return ( { "list" : sorted_l , "referer" : sorted_r } )


signature:
def batsorted ( referer , * lists , ** kwargs ) :
    '''from elist . elist import *
 referer = [ 4,2,3,1]
 l1 = [ ' a ' , ' b ' , ' c ' , ' d ' ]
 l2 = [ 100,200,300,400]
 l3 = [ ' A ' , ' B ' , ' A ' , ' B ' ]
 nl1 , nl2 , nl3 = batsorted ( referer , l1 , l2 , l3)
 nl1
 nl2
 nl3
 nl1 , nl2 , nl3 = batsorted ( referer , l1 , l2 , l3 , reverse = True )
 nl1
 nl2
 nl3
 # # # # the batsorted will not modify the original lists
 l1
 l2
 l3'''

implementation:
if ( 'reverse' in kwargs ) :
    reverse = kwargs [ 'reverse' ]
else :
    reverse = False
length = referer . __len__ ( )
indexes = list ( range ( 0 , length ) )
rslt = sorted_refer_to ( indexes , referer , reverse = reverse )
referer = rslt [ 'referer' ]
indexes = rslt [ 'list' ]
rslt = [ ]
lists = copy . deepcopy ( list ( lists ) )
for i in range ( 0 , lists . __len__ ( ) ) :
    l = lists [ i ]
    nl = [ ]
    for j in range ( 0 , length ) :
        loc = indexes [ j ]
        nl . append ( l [ loc ] )
    rslt . append ( nl )
return ( tuple ( rslt ) )


signature:
def sortDictList ( dictList , ** kwargs ) :
    '''students = [
 { ' name ' : ' john ' , ' class ' : ' A ' , ' year ' : 15 } ,
 { ' name ' : ' jane ' , ' class ' : ' B ' , ' year ' : 12 } ,
 { ' name ' : ' dave ' , ' class ' : ' B ' , ' year ' : 10}
 rslt = sortDictList ( students , cond _ keys = [ ' name ' , ' class ' , ' year ' ] )
 pobj ( rslt )
 rslt = sortDictList ( students , cond _ keys = [ ' name ' , ' year ' , ' class ' ] )
 pobj ( rslt )
 rslt = sortDictList ( students , cond _ keys = [ ' class ' , ' name ' , ' year ' ] )
 pobj ( rslt )
 rslt = sortDictList ( students , cond _ keys = [ ' class ' , ' year ' , ' name ' ] )
 pobj ( rslt )
 rslt = sortDictList ( students , cond _ keys = [ ' year ' , ' name ' , ' class ' ] )
 pobj ( rslt )
 rslt = sortDictList ( students , cond _ keys = [ ' year ' , ' name ' , ' class ' ] )
 pobj ( rslt )'''

implementation:
def default_eq_func ( value1 , value2 ) :
    cond = ( value1 == value2 )
    return ( cond )
def default_gt_func ( value1 , value2 ) :
    cond = ( value1 > value2 )
    return ( cond )
def default_lt_func ( value1 , value2 ) :
    cond = ( value1 < value2 )
    return ( cond )
if ( 'eq_func' in kwargs ) :
    eq_func = kwargs [ 'eq_func' ]
else :
    eq_func = default_eq_func
if ( 'gt_func' in kwargs ) :
    gt_func = kwargs [ 'gt_func' ]
else :
    gt_func = default_gt_func
if ( 'lt_func' in kwargs ) :
    lt_func = kwargs [ 'lt_func' ]
else :
    lt_func = default_lt_func
if ( 'reverse' in kwargs ) :
    reverse = kwargs [ 'reverse' ]
else :
    reverse = False
keys = kwargs [ 'cond_keys' ]
def cmp_dict ( d1 , d2 ) :
    length = keys . __len__ ( )
    for i in range ( 0 , length ) :
        key = keys [ i ]
        cond = eq_func ( d1 [ key ] , d2 [ key ] )
        if ( cond ) :
            pass
        else :
            cond = gt_func ( d1 [ key ] , d2 [ key ] )
            if ( cond ) :
                return ( 1 )
            else :
                return ( - 1 )
    return ( 0 )
ndl = dictList
ndl = sorted ( ndl , key = functools . cmp_to_key ( cmp_dict ) , reverse = reverse )
return ( ndl )


signature:
def index_firstnot ( ol , value ) :
    '''from elist . elist import *
 ol = [ 1 , ' a ' , 3 , ' a ' , 4 , ' a ' , 5]
 index _ firstnot ( ol , ' a ' )
 # # # # index _ firstnot , array _ indexnot , indexOfnot are the same
 array _ indexnot ( ol , ' a ' )
 indexOfnot ( ol , ' a ' )'''

implementation:
length = ol . __len__ ( )
for i in range ( 0 , length ) :
    if ( value == ol [ i ] ) :
        pass
    else :
        return ( i )
return ( None )


signature:
def index_last ( ol , value ) :
    '''from elist . elist import *
 ol = [ 1 , ' a ' , 3 , ' a ' , 4 , ' a ' , 5]
 index _ last ( ol , ' a ' )
 # # # # lastIndexOf is the same as index _ last
 lastIndexOf ( ol , ' a ' )'''

implementation:
length = ol . __len__ ( )
for i in range ( length - 1 , - 1 , - 1 ) :
    if ( value == ol [ i ] ) :
        return ( i )
    else :
        pass
return ( None )


signature:
def index_lastnot ( ol , value ) :
    '''from elist . elist import *
 ol = [ 1 , ' a ' , 3 , ' a ' , 4 , ' a ' , 5]
 index _ lastnot ( ol , ' a ' )
 # # # # lastIndexOfnot is the same as index _ lastnot
 lastIndexOfnot ( ol , ' a ' )'''

implementation:
length = ol . __len__ ( )
for i in range ( length - 1 , - 1 , - 1 ) :
    if ( value == ol [ i ] ) :
        pass
    else :
        return ( i )
return ( None )


signature:
def index_whichnot ( ol , value , which ) :
    '''from elist . elist import *
 ol = [ 1 , ' a ' , 3 , ' a ' , 4 , ' a ' , 5]
 index _ whichnot ( ol , ' a ' , 0)
 index _ whichnot ( ol , ' a ' , 1)
 index _ whichnot ( ol , ' a ' , 2)'''

implementation:
length = ol . __len__ ( )
seq = - 1
for i in range ( 0 , length ) :
    if ( value == ol [ i ] ) :
        pass
    else :
        seq = seq + 1
        if ( seq == which ) :
            return ( i )
        else :
            pass
return ( None )


signature:
def indexes_all ( ol , value ) :
    '''from elist . elist import *
 ol = [ 1 , ' a ' , 3 , ' a ' , 4 , ' a ' , 5]
 indexes _ all ( ol , ' a ' )'''

implementation:
length = ol . __len__ ( )
indexes = [ ]
for i in range ( 0 , length ) :
    if ( value == ol [ i ] ) :
        indexes . append ( i )
    else :
        pass
return ( indexes )


signature:
def indexes_some ( ol , value , * seqs ) :
    '''from elist . elist import *
 ol = [ 1 , ' a ' , 3 , ' a ' , 4 , ' a ' , 5]
 indexes _ some ( ol , ' a ' , 0,2)
 indexes _ some ( ol , ' a ' , 0,1)
 indexes _ some ( ol , ' a ' , 1,2)
 indexes _ some ( ol , ' a ' , 3,4)'''

implementation:
seqs = list ( seqs )
length = ol . __len__ ( )
indexes = [ ]
seq = - 1
for i in range ( 0 , length ) :
    if ( value == ol [ i ] ) :
        seq = seq + 1
        if ( seq in seqs ) :
            indexes . append ( i )
        else :
            pass
    else :
        pass
return ( indexes )


signature:
def first_continuous_indexesnot_slice ( ol , value ) :
    '''from elist . elist import *
 ol = [ " a " , 0,1 , " a " , " a " , 2,3 , " a " , 4 , " a " , " a " , " a " , 5]
 first _ continuous _ indexesnot _ slice ( ol , " a " )'''

implementation:
length = ol . __len__ ( )
begin = None
slice = [ ]
for i in range ( 0 , length ) :
    if ( not ( ol [ i ] == value ) ) :
        begin = i
        break
    else :
        pass
if ( begin == None ) :
    return ( None )
else :
    slice . append ( begin )
    for i in range ( begin + 1 , length ) :
        if ( not ( ol [ i ] == value ) ) :
            slice . append ( i )
        else :
            break
return ( slice )


signature:
def last_continuous_indexes_slice ( ol , value ) :
    '''from elist . elist import *
 ol = [ 1 , " a " , " a " , 2,3 , " a " , 4 , " a " , " a " , " a " , 5]
 last _ continuous _ indexes _ slice ( ol , " a " )'''

implementation:
length = ol . __len__ ( )
end = None
slice = [ ]
for i in range ( length - 1 , - 1 , - 1 ) :
    if ( ol [ i ] == value ) :
        end = i
        break
    else :
        pass
if ( end == None ) :
    return ( None )
else :
    slice . append ( end )
    for i in range ( end - 1 , - 1 , - 1 ) :
        if ( ol [ i ] == value ) :
            slice . append ( i )
        else :
            break
slice . reverse ( )
return ( slice )


signature:
def which_continuous_indexes_slice ( ol , value , which ) :
    '''from elist . elist import *
 ol = [ 1 , " a " , " a " , 2,3 , " a " , 4 , " a " , " a " , " a " , 5]
 which _ continuous _ indexes _ slice ( ol , " a " , 0)
 which _ continuous _ indexes _ slice ( ol , " a " , 1)
 which _ continuous _ indexes _ slice ( ol , " a " , 2)
 which _ continuous _ indexes _ slice ( ol , " a " , 3)
 which _ continuous _ indexes _ slice ( ol , " b " , 0)'''

implementation:
length = ol . __len__ ( )
seq = - 1
cursor = 0
begin = None
slice = [ ]
while ( cursor < length ) :
    cond1 = ( ol [ cursor ] == value )
    cond2 = ( begin == None )
    if ( cond1 & cond2 ) :
        begin = cursor
        slice . append ( cursor )
        cursor = cursor + 1
    elif ( cond1 & ( not ( cond2 ) ) ) :
        slice . append ( cursor )
        cursor = cursor + 1
    elif ( ( not ( cond1 ) ) & ( not ( cond2 ) ) ) :
        seq = seq + 1
        if ( seq == which ) :
            return ( slice )
        else :
            cursor = cursor + 1
            begin = None
            slice = [ ]
    else :
        cursor = cursor + 1
if ( slice ) :
    seq = seq + 1
else :
    pass
if ( seq == which ) :
    return ( slice )
else :
    return ( [ ] )


signature:
def seqs_continuous_indexesnot_slices ( ol , value , seqs ) :
    '''from elist . elist import *
 ol = [ 1 , " a " , " a " , 2,3 , " a " , 4 , " a " , " a " , " a " , 5]
 seqs _ continuous _ indexesnot _ slices ( ol , " a " , { 0,2 } )'''

implementation:
rslt = [ ]
length = ol . __len__ ( )
seq = - 1
cursor = 0
begin = None
slice = [ ]
while ( cursor < length ) :
    cond1 = not ( ol [ cursor ] == value )
    cond2 = ( begin == None )
    if ( cond1 & cond2 ) :
        begin = cursor
        slice . append ( cursor )
    elif ( cond1 & ( not ( cond2 ) ) ) :
        slice . append ( cursor )
    elif ( ( not ( cond1 ) ) & ( not ( cond2 ) ) ) :
        seq = seq + 1
        if ( seq in seqs ) :
            rslt . append ( slice )
        else :
            pass
        begin = None
        slice = [ ]
    else :
        pass
    cursor = cursor + 1
if ( slice ) :
    seq = seq + 1
    if ( seq in seqs ) :
        rslt . append ( slice )
    else :
        pass
else :
    pass
return ( rslt )


signature:
def all_continuous_indexes_slices ( ol , value ) :
    '''from elist . elist import *
 ol = [ 1 , " a " , " a " , 2,3 , " a " , 4 , " a " , " a " , " a " , 5]
 all _ continuous _ indexes _ slices ( ol , " a " )'''

implementation:
rslt = [ ]
length = ol . __len__ ( )
cursor = 0
begin = None
slice = [ ]
while ( cursor < length ) :
    cond1 = ( ol [ cursor ] == value )
    cond2 = ( begin == None )
    if ( cond1 & cond2 ) :
        begin = cursor
        slice . append ( cursor )
    elif ( cond1 & ( not ( cond2 ) ) ) :
        slice . append ( cursor )
    elif ( ( not ( cond1 ) ) & ( not ( cond2 ) ) ) :
        rslt . append ( slice )
        begin = None
        slice = [ ]
    else :
        pass
    cursor = cursor + 1
if ( slice ) :
    rslt . append ( slice )
else :
    pass
return ( rslt )


signature:
def shift ( ol , ** kwargs ) :
    '''from elist . jprint import pobj
 from elist . elist import *
 ol = [ 1,2,3,4]
 id ( ol )
 rslt = shift ( ol )
 pobj ( rslt )
 ol
 id ( ol )
 id ( rslt [ ' list ' ] )
 ol = [ 1,2,3,4]
 id ( ol )
 rslt = shift ( ol , mode = " original " )
 rslt
 ol
 id ( ol )'''

implementation:
if ( 'mode' in kwargs ) :
    mode = kwargs [ 'mode' ]
else :
    mode = "new"
length = ol . __len__ ( )
rslt = pop ( ol , 0 , mode = mode )
return ( rslt )


signature:
def pop ( ol , index , ** kwargs ) :
    '''from elist . jprint import pobj
 from elist . elist import *
 ol = [ 1,2,3,4]
 id ( ol )
 rslt = pop ( ol , 2)
 pobj ( rslt )
 ol
 id ( ol )
 id ( rslt [ ' list ' ] )
 ol = [ 1,2,3,4]
 id ( ol )
 rslt = pop ( ol , 2 , mode = " original " )
 rslt
 ol
 id ( ol )'''

implementation:
index = uniform_index ( index , ol . __len__ ( ) )
if ( 'mode' in kwargs ) :
    mode = kwargs [ "mode" ]
else :
    mode = "new"
if ( mode == "new" ) :
    new = copy . deepcopy ( ol )
    popped = new . pop ( index )
    return ( { 'popped' : popped , 'list' : new } )
else :
    popped = ol . pop ( index )
    return ( popped )


signature:
def cond_pop ( ol , index , ** kwargs ) :
    '''from elist . jprint import pobj
 from elist . elist import *
 ol = [ { ' data ' : 0 ; ' type ' : ' number ' } , { ' data ' : ' x ' ; ' type ' : ' str ' } , { ' data ' : ' y ' ; ' type ' : ' str ' } , 4]
 # cond _ func _ args is a array
 def cond _ func ( index , value , cond _ func _ args ) :'''

implementation:
cond_func = kwargs [ 'cond_func' ]
cond_func_args = kwargs [ 'cond_func_args' ]
index = uniform_index ( index , ol . __len__ ( ) )
if ( 'mode' in kwargs ) :
    mode = kwargs [ "mode" ]
else :
    mode = "new"
value = ol [ index ]
cond = cond_func ( index , value , * cond_func_args )
if ( mode == "new" ) :
    new = copy . deepcopy ( ol )
    if ( cond ) :
        popped = new . pop ( index )
    else :
        popped = new
    return ( { 'popped' : popped , 'list' : new } )
else :
    if ( cond ) :
        popped = ol . pop ( index )
    else :
        popped = ol
    return ( popped )


signature:
def pop_range ( ol , start_index , end_index , ** kwargs ) :
    '''from elist . jprint import pobj
 from elist . elist import *
 ol = [ 1,2,3,4,5,6]
 id ( ol )
 rslt = pop _ range ( ol , 2,4)
 ol
 id ( ol )
 id ( rslt [ ' list ' ] )
 ol = [ 1,2,3,4,5,6]
 id ( ol )
 rslt = pop _ range ( ol , 2,4 , mode = " original " )
 rslt
 ol
 id ( ol )'''

implementation:
length = ol . __len__ ( )
start_index = uniform_index ( start_index , length )
end_index = uniform_index ( end_index , length )
if ( 'mode' in kwargs ) :
    mode = kwargs [ "mode" ]
else :
    mode = "new"
if ( mode == "new" ) :
    cpol = copy . deepcopy ( ol )
    new = [ ]
    popped = [ ]
    for i in range ( 0 , start_index ) :
        new . append ( cpol [ i ] )
    for i in range ( start_index , end_index ) :
        popped . append ( cpol [ i ] )
    for i in range ( end_index , length ) :
        new . append ( cpol [ i ] )
    return ( { 'popped' : popped , 'list' : new } )
else :
    tmp = [ ]
    popped = [ ]
    for i in range ( 0 , start_index ) :
        tmp . append ( ol [ i ] )
    for i in range ( start_index , end_index ) :
        popped . append ( ol [ i ] )
    for i in range ( end_index , length ) :
        tmp . append ( ol [ i ] )
    ol . clear ( )
    for i in range ( 0 , tmp . __len__ ( ) ) :
        ol . append ( tmp [ i ] )
    return ( popped )


signature:
def pop_indexes ( ol , indexes , ** kwargs ) :
    '''from elist . jprint import pobj
 from elist . elist import *
 ol = [ 1,2,3,4,5,6]
 id ( ol )
 rslt = pop _ indexes ( ol , { 0 , - 3,5 } )
 ol
 id ( ol )
 id ( rslt [ ' list ' ] )
 ol = [ 1,2,3,4,5,6]
 id ( ol )
 rslt = pop _ indexes ( ol , { 0 , - 3,5 } , mode = " original " )
 rslt
 ol
 id ( ol )'''

implementation:
length = ol . __len__ ( )
indexes = list ( map ( lambda index : uniform_index ( index , length ) , list ( indexes ) ) )
if ( 'mode' in kwargs ) :
    mode = kwargs [ "mode" ]
else :
    mode = "new"
if ( mode == "new" ) :
    cpol = copy . deepcopy ( ol )
    new = [ ]
    popped = [ ]
    for i in range ( 0 , length ) :
        if ( i in indexes ) :
            popped . append ( cpol [ i ] )
        else :
            new . append ( cpol [ i ] )
    return ( { 'popped' : popped , 'list' : new } )
else :
    tmp = [ ]
    popped = [ ]
    for i in range ( 0 , length ) :
        if ( i in indexes ) :
            popped . append ( ol [ i ] )
        else :
            tmp . append ( ol [ i ] )
    ol . clear ( )
    for i in range ( 0 , tmp . __len__ ( ) ) :
        ol . append ( tmp [ i ] )
    return ( popped )


signature:
def remove_first ( ol , value , ** kwargs ) :
    '''from elist . jprint import pobj
 from elist . elist import *
 ol = [ 1 , ' a ' , 3 , ' a ' , 5 , ' a ' ]
 id ( ol )
 new = remove _ first ( ol , ' a ' )
 ol
 new
 id ( ol )
 id ( new )
 ol = [ 1 , ' a ' , 3 , ' a ' , 5 , ' a ' ]
 id ( ol )
 rslt = remove _ first ( ol , ' a ' , mode = " original " )
 ol
 rslt
 id ( ol )
 id ( rslt )
 # # # # array _ remove is the same as remove _ first'''

implementation:
if ( 'mode' in kwargs ) :
    mode = kwargs [ "mode" ]
else :
    mode = "new"
if ( mode == "new" ) :
    new = copy . deepcopy ( ol )
    new . remove ( value )
    return ( new )
else :
    ol . remove ( value )
    return ( ol )


signature:
def remove_firstnot ( ol , value , ** kwargs ) :
    '''from elist . jprint import pobj
 from elist . elist import *
 ol = [ 1 , ' a ' , 3 , ' a ' , 5 , ' a ' ]
 id ( ol )
 new = remove _ firstnot ( ol , ' a ' )
 ol
 new
 id ( ol )
 id ( new )
 ol = [ 1 , ' a ' , 3 , ' a ' , 5 , ' a ' ]
 id ( ol )
 rslt = remove _ firstnot ( ol , ' a ' , mode = " original " )
 ol
 rslt
 id ( ol )
 id ( rslt )
 # # # # array _ removenot is the same as remove _ firstnot'''

implementation:
if ( 'mode' in kwargs ) :
    mode = kwargs [ "mode" ]
else :
    mode = "new"
length = ol . __len__ ( )
if ( mode == "new" ) :
    new = copy . deepcopy ( ol )
    for i in range ( 0 , length ) :
        if ( new [ i ] == value ) :
            pass
        else :
            new . pop ( i )
            return ( new )
    return ( new )
else :
    for i in range ( 0 , length ) :
        if ( ol [ i ] == value ) :
            pass
        else :
            ol . pop ( i )
            return ( ol )
    return ( ol )


signature:
def remove_last ( ol , value , ** kwargs ) :
    '''from elist . elist import *
 ol = [ 1 , ' a ' , 3 , ' a ' , 5 , ' a ' ]
 id ( ol )
 new = remove _ last ( ol , ' a ' )
 ol
 new
 id ( ol )
 id ( new )
 ol = [ 1 , ' a ' , 3 , ' a ' , 5 , ' a ' ]
 id ( ol )
 rslt = remove _ last ( ol , ' a ' , mode = " original " )
 ol
 rslt
 id ( ol )
 id ( rslt )'''

implementation:
if ( 'mode' in kwargs ) :
    mode = kwargs [ "mode" ]
else :
    mode = "new"
new = copy . deepcopy ( ol )
new . reverse ( )
new . remove ( value )
new . reverse ( )
if ( mode == "new" ) :
    return ( new )
else :
    ol . clear ( )
    ol . extend ( new )
    return ( ol )


signature:
def remove_which ( ol , value , which , ** kwargs ) :
    '''from elist . elist import *
 ol = [ 1 , ' a ' , 3 , ' a ' , 5 , ' a ' ]
 id ( ol )
 new = remove _ which ( ol , ' a ' , 1)
 ol
 new
 id ( ol )
 id ( new )
 ol = [ 1 , ' a ' , 3 , ' a ' , 5 , ' a ' ]
 id ( ol )
 rslt = remove _ which ( ol , ' a ' , 1 , mode = " original " )
 ol
 rslt
 id ( ol )
 id ( rslt )'''

implementation:
if ( 'mode' in kwargs ) :
    mode = kwargs [ "mode" ]
else :
    mode = "new"
new = copy . deepcopy ( ol )
length = ol . __len__ ( )
if ( mode == "new" ) :
    l = new
else :
    l = ol
seq = - 1
for i in range ( 0 , length ) :
    if ( ol [ i ] == value ) :
        seq = seq + 1
        if ( seq == which ) :
            l . pop ( i )
            break
        else :
            pass
    else :
        pass
return ( l )


signature:
def remove_some ( ol , value , * seqs , ** kwargs ) :
    '''from elist . elist import *
 ol = [ 1 , ' a ' , 3 , ' a ' , 5 , ' a ' , 6 , ' a ' ]
 id ( ol )
 new = remove _ some ( ol , ' a ' , 1,3)
 ol
 new
 id ( ol )
 id ( new )
 ol = [ 1 , ' a ' , 3 , ' a ' , 5 , ' a ' , 6 , ' a ' ]
 id ( ol )
 rslt = remove _ some ( ol , ' a ' , 1,3 , mode = " original " )
 ol
 rslt
 id ( ol )
 id ( rslt )'''

implementation:
if ( 'mode' in kwargs ) :
    mode = kwargs [ "mode" ]
else :
    mode = "new"
seqs = list ( seqs )
new = [ ]
length = ol . __len__ ( )
seq = - 1
cpol = copy . deepcopy ( ol )
for i in range ( 0 , length ) :
    if ( cpol [ i ] == value ) :
        seq = seq + 1
        if ( seq in seqs ) :
            pass
        else :
            new . append ( cpol [ i ] )
    else :
        new . append ( cpol [ i ] )
if ( mode == "new" ) :
    return ( new )
else :
    ol . clear ( )
    ol . extend ( new )
    return ( ol )


signature:
def remove_all ( ol , value , ** kwargs ) :
    '''from elist . elist import *
 ol = [ 1 , ' a ' , 3 , ' a ' , 5 , ' a ' , 6 , ' a ' ]
 id ( ol )
 new = remove _ all ( ol , ' a ' )
 ol
 new
 id ( ol )
 id ( new )
 ol = [ 1 , ' a ' , 3 , ' a ' , 5 , ' a ' , 6 , ' a ' ]
 id ( ol )
 rslt = remove _ all ( ol , ' a ' , mode = " original " )
 ol
 rslt
 id ( ol )
 id ( rslt )'''

implementation:
if ( 'mode' in kwargs ) :
    mode = kwargs [ "mode" ]
else :
    mode = "new"
new = [ ]
length = ol . __len__ ( )
cpol = copy . deepcopy ( ol )
for i in range ( 0 , length ) :
    if ( cpol [ i ] == value ) :
        pass
    else :
        new . append ( cpol [ i ] )
if ( mode == "new" ) :
    return ( new )
else :
    ol . clear ( )
    ol . extend ( new )
    return ( ol )


signature:
def remove_many ( ol , values , seqs , ** kwargs ) :
    '''from elist . elist import *
 ol = [ 1 , ' a ' , 3 , ' b ' , 5 , ' a ' , 6 , ' a ' , 7 , ' b ' , 8 , ' b ' , 9]
 id ( ol )
 new = remove _ many ( ol , [ ' a ' , ' b ' ] , [ 1,2 ] )
 ol
 new
 id ( ol )
 id ( new )
 ol = [ 1 , ' a ' , 3 , ' b ' , 5 , ' a ' , 6 , ' a ' , 7 , ' b ' , 8 , ' b ' , 9]
 id ( ol )
 rslt = remove _ many ( ol , [ ' a ' , ' b ' ] , [ 1,2 ] , mode = " original " )
 ol
 rslt
 id ( ol )
 id ( rslt )'''

implementation:
if ( 'mode' in kwargs ) :
    mode = kwargs [ "mode" ]
else :
    mode = "new"
values = copy . deepcopy ( values )
seqs = copy . deepcopy ( seqs )
cursors = [ - 1 ] * values . __len__ ( )
new = [ ]
length = ol . __len__ ( )
cpol = copy . deepcopy ( ol )
for i in range ( 0 , length ) :
    label = True
    for j in range ( 0 , cursors . __len__ ( ) ) :
        which = seqs [ j ]
        value = values [ j ]
        if ( cpol [ i ] == value ) :
            cursors [ j ] = cursors [ j ] + 1
            if ( cursors [ j ] == which ) :
                label = False
                break
            else :
                pass
        else :
            pass
    if ( label ) :
        new . append ( cpol [ i ] )
    else :
        pass
if ( mode == "new" ) :
    return ( new )
else :
    ol . clear ( )
    ol . extend ( new )
    return ( ol )


signature:
def cond_remove_all ( ol , ** kwargs ) :
    '''from elist . elist import *
 ol = [ 1 , ' X ' , 3 , ' b ' , 5 , ' c ' , 6 , ' A ' , 7 , ' b ' , 8 , ' B ' , 9]
 id ( ol )
 def afterCH ( ele , ch ) :
 cond = ( ord ( str ( ele ) ) > ord ( ch ) )
 return ( cond )
 new = cond _ remove _ all ( ol , cond _ func = afterCH , cond _ func _ args = [ ' B ' ] )
 ol
 new
 id ( ol )
 id ( new )
 ol = [ 1 , ' X ' , 3 , ' b ' , 5 , ' c ' , 6 , ' A ' , 7 , ' b ' , 8 , ' B ' , 9]
 id ( ol )
 rslt = cond _ remove _ all ( ol , cond _ func = afterCH , cond _ func _ args = [ ' B ' ] , mode = ' original ' )
 ol
 rslt
 id ( ol )
 id ( rslt )'''

implementation:
cond_func = kwargs [ 'cond_func' ]
if ( 'cond_func_args' in kwargs ) :
    cond_func_args = kwargs [ 'cond_func_args' ]
else :
    cond_func_args = [ ]
if ( 'mode' in kwargs ) :
    mode = kwargs [ "mode" ]
else :
    mode = "new"
new = copy . deepcopy ( ol )
selected = find_all ( new , cond_func , * cond_func_args )
selected_indexes = array_map ( selected , lambda ele : ele [ 'index' ] )
new = pop_indexes ( new , selected_indexes ) [ 'list' ]
if ( mode == "new" ) :
    return ( new )
else :
    ol . clear ( )
    ol . extend ( new )
    return ( ol )


signature:
def cond_remove_some ( ol , * some , ** kwargs ) :
    '''from elist . elist import *
 ol = [ 1 , ' X ' , 3 , ' b ' , 5 , ' c ' , 6 , ' A ' , 7 , ' b ' , 8 , ' B ' , 9]
 id ( ol )
 def afterCH ( ele , ch ) :
 cond = ( ord ( str ( ele ) ) > ord ( ch ) )
 return ( cond )
 new = cond _ remove _ some ( ol , 0,2 , cond _ func = afterCH , cond _ func _ args = [ ' B ' ] )
 ol
 new
 id ( ol )
 id ( new )
 ol = [ 1 , ' X ' , 3 , ' b ' , 5 , ' c ' , 6 , ' A ' , 7 , ' b ' , 8 , ' B ' , 9]
 id ( ol )
 rslt = cond _ remove _ some ( ol , 0,2 , cond _ func = afterCH , cond _ func _ args = [ ' B ' ] , mode = ' original ' )
 ol
 rslt
 id ( ol )
 id ( rslt )'''

implementation:
cond_func = kwargs [ 'cond_func' ]
if ( 'cond_func_args' in kwargs ) :
    cond_func_args = kwargs [ 'cond_func_args' ]
else :
    cond_func_args = [ ]
if ( 'mode' in kwargs ) :
    mode = kwargs [ "mode" ]
else :
    mode = "new"
seqs = list ( some )
rslt = cond_remove_seqs ( ol , seqs , cond_func = cond_func , cond_func_args = cond_func_args )
return ( rslt )


signature:
def init ( len , default_element = None ) :
    '''from elist . elist import *
 init ( 5)
 init ( 5 , " x " )'''

implementation:
rslt = [ ]
for i in range ( 0 , len ) :
    rslt . append ( copy . deepcopy ( default_element ) )
return ( rslt )


signature:
def array_from ( obj , func , * args ) :
    '''from elist . elist import *
 array _ from ( " abcd " , None )
 def map _ func ( ele , x , y ) :
 return ( int ( ele ) + x + y )
 array _ from ( " 1234 " , map _ func , 1000,100)
 def map _ func ( ele ) :
 return ( int ( ele ) * 2)
 array _ from ( " 1234 " , map _ func )
 array _ from ( " 1234 " , None )'''

implementation:
if ( func ) :
    l = list ( obj )
    rslt = list ( map ( lambda ele : func ( ele , * args ) , l ) )
    return ( rslt )
else :
    return ( list ( obj ) )


signature:
def copy_within ( ol , target , start = None , end = None ) :
    '''from elist . elist import *
 ol = [ 1 , 2 , 3 , 4 , 5]
 id ( ol )
 rslt = copyWithin ( ol , 0,3,4)
 rslt
 id ( rslt )
 ol = [ 1 , 2 , 3 , 4 , 5]
 id ( ol )
 rslt = copyWithin ( ol , 0,3)
 rslt
 id ( rslt )
 ol = [ 1 , 2 , 3 , 4 , 5]
 id ( ol )
 rslt = copyWithin ( ol , - 2)
 rslt
 id ( rslt )
 # # # # copyWithin is the same as copy _ within'''

implementation:
length = ol . __len__ ( )
if ( start == None ) :
    start = 0
else :
    pass
if ( end == None ) :
    end = length
else :
    pass
target = uniform_index ( target , length )
start = uniform_index ( start , length )
end = uniform_index ( end , length )
cplen = end - start
cpend = target + cplen
if ( target + cplen > length ) :
    cpend = length
else :
    pass
shift = start - target
if ( shift >= 0 ) :
    for i in range ( target , cpend ) :
        ol [ i ] = ol [ i + shift ]
else :
    for i in range ( cpend - 1 , target - 1 , - 1 ) :
        ol [ i ] = ol [ i + shift ]
return ( ol )


signature:
def comprise ( list1 , list2 , ** kwargs ) :
    '''from elist . elist import *
 comprise ( [ 1,2,3,4,5 ] , [ 2,3,4 ] , mode = " loose " )
 comprise ( [ 1,2,3,4,5 ] , [ 2,3,4 ] )
 comprise ( [ 1,2,3,4,5 ] , [ 2,3,4 ] , mode = " strict " )
 comprise ( [ 1,2,3,4,5 ] , [ 1,2,3,4 ] , mode = " strict " )
 # not recursive , only one level
 # please refer to ListTree . search for recursive support'''

implementation:
if ( 'mode' in kwargs ) :
    mode = kwargs [ 'mode' ]
else :
    mode = "loose"
len_1 = list1 . __len__ ( )
len_2 = list2 . __len__ ( )
if ( len_2 > len_1 ) :
    return ( False )
else :
    if ( mode == "strict" ) :
        if ( list2 == list1 [ : len_2 ] ) :
            return ( True )
        else :
            return ( False )
    else :
        end = len_1 - len_2
        for i in range ( 0 , end + 1 ) :
            if ( list2 == list1 [ i : ( i + len_2 ) ] ) :
                return ( True )
            else :
                pass
return ( False )


signature:
def entries ( ol ) :
    '''from elist . elist import *
 ol = [ ' a ' , ' b ' , ' c ' ]
 rslt = entries ( ol )
 rslt'''

implementation:
rslt = [ ]
length = ol . __len__ ( )
for i in range ( 0 , length ) :
    entry = [ i , ol [ i ] ]
    rslt . append ( entry )
return ( rslt )


signature:
def splice ( ol , start , deleteCount , * eles , ** kwargs ) :
    '''from elist . elist import *
 ol = [ " angel " , " clown " , " mandarin " , " surgeon " ]
 id ( ol )
 new = splice ( ol , 2,0 , " drum " )
 new
 id ( new )
 ol = [ " angel " , " clown " , " mandarin " , " surgeon " ]
 id ( ol )
 new = splice ( ol , 2,1 , " drum " , mode = " original " )
 new
 id ( new )
 ol = [ 1,2,3,4,5,6]
 id ( ol )
 new = splice ( ol , 2,2,77,777)
 new
 id ( new )'''

implementation:
if ( 'mode' in kwargs ) :
    mode = kwargs [ 'mode' ]
else :
    mode = "new"
length = ol . __len__ ( )
new = copy . deepcopy ( ol )
if ( start >= length ) :
    eles = list ( eles )
    new . extend ( eles )
else :
    start = uniform_index ( start , length )
    end = start + deleteCount
    tmp = pop_range ( new , start , end , mode = "new" ) [ 'list' ]
    new = insert_some ( tmp , * eles , index = start , mode = "new" )
if ( mode == "new" ) :
    return ( new )
else :
    ol . clear ( )
    ol . extend ( new )
    return ( ol )


signature:
def slice ( ol , start , end = None , ** kwargs ) :
    '''from elist . elist import *
 ol = [ 1,2,3,4,5]
 id ( ol )
 new = slice ( ol , 2,4)
 new
 id ( new )
 id ( ol )
 rslt = slice ( ol , 1 , - 2 , mode = " original " )
 rslt
 id ( rslt )'''

implementation:
if ( 'mode' in kwargs ) :
    mode = kwargs [ 'mode' ]
else :
    mode = "new"
length = ol . __len__ ( )
new = copy . deepcopy ( ol )
if ( end == None ) :
    end = length
else :
    end = uniform_index ( end , length )
start = uniform_index ( start , length )
if ( mode == "new" ) :
    return ( new [ start : end ] )
else :
    ol . clear ( )
    ol . extend ( new [ start : end ] )
    return ( ol )


signature:
def join ( ol , separator = "," ) :
    '''from elist . elist import *
 ol = [ 1,2,3,4]
 join ( ol , separator = " - " )'''

implementation:
if ( ol . __len__ ( ) == 0 ) :
    return ( "" )
else :
    pass
cond = ( type ( ol [ 0 ] ) == type ( b'' ) )
if ( cond ) :
    rslt = b''
else :
    rslt = ""
length = ol . __len__ ( )
for i in range ( 0 , length - 1 ) :
    ele = ol [ i ]
    if ( cond ) :
        pass
    else :
        ele = str ( ele )
    rslt = rslt + ele + separator
if ( cond ) :
    rslt = rslt + ol [ length - 1 ]
else :
    rslt = rslt + str ( ol [ length - 1 ] )
return ( rslt )


signature:
def join2 ( ol , * sps ) :
    '''from elist . elist import *
 ol = [ 1,2,3,4]
 join2 ( ol , " - " , " + " , " * " )'''

implementation:
rslt = ""
length = ol . __len__ ( )
for i in range ( 0 , length - 1 ) :
    rslt = rslt + str ( ol [ i ] ) + sps [ i ]
rslt = rslt + str ( ol [ length - 1 ] )
return ( rslt )


signature:
def htmljoin ( ol , sp , ** kwargs ) :
    '''ol = [ 1,2,3,4]
 htmljoin ( ol , " option " , outer = " select " )'''

implementation:
if ( 'outer' in kwargs ) :
    outer = kwargs [ 'outer' ]
else :
    outer = ""
if ( outer ) :
    head = "<" + outer + ">"
    tail = "</" + outer + ">"
else :
    head = ""
    tail = ""
rslt = head
length = ol . __len__ ( )
begin = "<" + sp + ">"
end = "</" + sp + ">"
for i in range ( 0 , length ) :
    rslt = rslt + begin + str ( ol [ i ] ) + end
rslt = rslt + tail
return ( rslt )


signature:
def uniqualize ( l , ** kwargs ) :
    '''from elist . elist import *
 l = [ 1 , 2 , 2]
 new = uniqualize ( l )
 new
 id ( l )
 id ( new )
 l = [ 1 , 2 , 2]
 rslt = uniqualize ( l , mode = " original " )
 rslt
 id ( l )
 id ( rslt )'''

implementation:
if ( 'mode' in kwargs ) :
    mode = kwargs [ 'mode' ]
else :
    mode = 'new'
pt = copy . deepcopy ( l )
seqs = [ ]
freq = { }
for i in range ( 0 , pt . __len__ ( ) ) :
    v = pt [ i ]
    if ( v in freq ) :
        freq [ v ] = freq [ v ] + 1
    else :
        freq [ v ] = 0
        seqs . append ( i )
# # # # # 下面是影响速度的关键 , append特别耗时
npt = select_seqs ( pt , seqs )
pt = npt
if ( mode == 'new' ) :
    return ( npt )
else :
    l . clear ( )
    l . extend ( npt )
    return ( l )


signature:
def cond_uniqualize ( l , ** kwargs ) :
    '''from elist . elist import *
 l = [ ( ' BIGipServer ' , ' rd100 ' ) , ( ' TS013d8ed5 ' , ' 00A0 ' ) , ( ' BIGipServer ' , ' rd200 ' ) , ( ' TS013d8ed5 ' , ' 00B0 ' ) , ( ' SID ' , ' 1 ' ) , ( ' SID ' , ' 2 ' ) ]
 def cond _ func ( ele , * args ) :
 cond = ele [ 0]
 return ( cond )
 uniqualized = cond _ uniqualize ( l , cond _ func = cond _ func )
 pobj ( uniqualized )
 l = [ ( ' BIGipServer ' , ' rd100 ' ) , ( ' TS013d8ed5 ' , ' 00A0 ' ) , ( ' BIGipServer ' , ' rd200 ' ) , ( ' TS013d8ed5 ' , ' 00B0 ' ) , ( ' SID ' , ' 1 ' ) , ( ' SID ' , ' 2 ' ) ]
 reserved _ mapping = { ' BIGipServer ' : 0 , ' TS013d8ed5 ' : 1 , ' SID ' : 1}
 uniqualized = cond _ uniqualize ( l , cond _ func = cond _ func , reserved _ mapping = reserved _ mapping )
 pobj ( uniqualized )'''

implementation:
cond_func = kwargs [ 'cond_func' ]
if ( 'cond_func_args' in kwargs ) :
    cond_func_args = kwargs [ 'cond_func_args' ]
else :
    cond_func_args = [ ]
if ( 'reserved_mapping' in kwargs ) :
    reserved_mapping = kwargs [ 'reserved_mapping' ]
else :
    reserved_mapping = None
if ( 'mode' in kwargs ) :
    mode = kwargs [ 'mode' ]
else :
    mode = 'new'
desc = cond_value_indexes_mapping ( l , cond_func = cond_func , cond_func_args = cond_func_args , with_none = True )
keys = list ( desc . keys ( ) )
if ( None in keys ) :
    keys . remove ( None )
else :
    pass
rmapping = { }
for key in keys :
    rmapping [ key ] = 0
if ( reserved_mapping == None ) :
    pass
else :
    for key in reserved_mapping :
        rmapping [ key ] = reserved_mapping [ key ]
reserved_indexes = [ ]
for key in keys :
    indexes = desc [ key ]
    index = indexes [ rmapping [ key ] ]
    reserved_indexes . append ( index )
newcopy = copy . deepcopy ( l )
new = select_seqs ( newcopy , reserved_indexes )
if ( None in desc ) :
    for index in desc [ None ] :
        new . append ( newcopy [ index ] )
else :
    pass
if ( mode == "new" ) :
    return ( new )
else :
    ol . clear ( )
    ol . extend ( new )
    return ( ol )


implementation:
anum = arrays . __len__ ( )
rslt = [ ]
length = arrays [ 0 ] . __len__ ( )
for j in range ( 0 , length ) :
    for i in range ( 0 , anum ) :
        array = arrays [ i ]
        rslt . append ( array [ j ] )
return ( rslt )


signature:
def deinterleave ( ol , gnum ) :
    '''ol = [ 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9]
 deinterleave ( ol , 3)'''

implementation:
def test_func ( ele , index , interval , which ) :
    cond = ( index % interval == which )
    return ( cond )
rslt = [ ]
for i in range ( 0 , gnum ) :
    arr = cond_select_all2 ( ol , cond_func = test_func , cond_func_args = [ gnum , i ] )
    rslt . append ( arr )
return ( rslt )


signature:
def for_each ( ol , test_func , * args ) :
    '''from elist . elist import *
 def show _ func ( ele ) :
 print ( " < { 0 } > " . format ( ele ) )
 ol = [ 1,2,3,4]
 for _ each ( ol , show _ func )
 # # # # forEach is the same as for _ each
 # # # # forEach have no return value'''

implementation:
rslt = ( True , None )
length = ol . __len__ ( )
for i in range ( 0 , length ) :
    test_func ( ol [ i ] , * args )


signature:
def loose_in ( pl , k ) :
    '''pl = [ ' bcd ' , ' xabcxx ' , ' x ' , ' y ' ]
 loose _ in ( pl , ' abc ' )'''

implementation:
cond = some ( pl , lambda ele : ( k in ele ) ) [ 'cond' ]
return ( cond )


signature:
def select_loose_in ( pl , k ) :
    '''pl = [ ' bcd ' , ' xabcxx ' , ' x ' , ' y ' ]
 select _ loose _ in ( pl , ' abc ' )'''

implementation:
def cond_func ( ele , index , k ) :
    if ( type ( ele ) == type ( [ ] ) ) :
        cond = loose_in ( ele , k )
    else :
        cond = ( k in ele )
    return ( cond )
arr = cond_select_values_all2 ( pl , cond_func = cond_func , cond_func_args = [ k ] )
return ( arr )


signature:
def select_strict_in ( pl , k ) :
    '''pl = [ ' bcd ' , ' xabcxx ' , ' x ' , ' y ' ]
 select _ strict _ in ( pl , ' abc ' )'''

implementation:
def cond_func ( ele , index , k ) :
    if ( type ( ele ) == type ( [ ] ) ) :
        cond = ( k in ele )
    else :
        cond = ( k == ele )
    return ( cond )
arr = cond_select_values_all2 ( pl , cond_func = cond_func , cond_func_args = [ k ] )
return ( arr )


signature:
def regex_in ( pl , regex ) :
    '''regex = re . compile ( " ^ [ a - z ] + $ " )
 pl = [ ' b1c3d ' , ' xab15cxx ' , ' 1x ' , ' y2 ' ]
 regex _ in ( pl , regex )
 regex = re . compile ( " ^ [ 0-9a - z ] + $ " )
 pl = [ ' b1c3d ' , ' xab15cxx ' , ' 1x ' , ' y2 ' ]
 regex _ in ( pl , regex )'''

implementation:
def cond_func ( ele , regex ) :
    m = regex . search ( ele )
    if ( m == None ) :
        return ( False )
    else :
        return ( True )
cond = some ( pl , cond_func , regex ) [ 'cond' ]
return ( cond )


signature:
def select_regex_in ( pl , regex ) :
    '''regex = re . compile ( " ^ x . * x $ " )
 pl = [ ' bcd ' , ' xabcxx ' , ' xx ' , ' y ' ]
 select _ regex _ in ( pl , ' abc ' )'''

implementation:
def cond_func ( ele , index , regex ) :
    if ( type ( ele ) == type ( [ ] ) ) :
        cond = regex_in ( ele , regex )
    else :
        m = regex . search ( ele )
        if ( m == None ) :
            cond = False
        else :
            cond = True
    return ( cond )
arr = cond_select_values_all2 ( pl , cond_func = cond_func , cond_func_args = [ regex ] )
return ( arr )


signature:
def some ( ol , test_func , * args ) :
    '''from elist . elist import *
 def test _ func ( ele , x ) :
 cond = ( ele > x )
 return ( cond )
 ol = [ 1,2,3,4]
 some ( ol , test _ func , 3)
 ol = [ 1,2,1,3]
 some ( ol , test _ func , 3)'''

implementation:
rslt = { 'cond' : False , 'index' : None }
length = ol . __len__ ( )
for i in range ( 0 , length ) :
    cond = test_func ( ol [ i ] , * args )
    if ( cond ) :
        return ( { 'cond' : True , 'index' : i } )
    else :
        pass
return ( rslt )


signature:
def fill ( ol , value , start = None , end = None , ** kwargs ) :
    '''from elist . elist import *
 ol = [ 1 , 2 , 3,4,5]
 id ( ol )
 rslt = fill ( ol , 4)
 rslt
 id ( rslt )
 ol = [ 1 , 2 , 3,4,5]
 id ( ol )
 rslt = fill ( ol , 4,1)
 rslt
 id ( rslt )
 ol = [ 1 , 2 , 3,4,5]
 id ( ol )
 rslt = fill ( ol , 6,1,3 , mode = " original " )
 rslt
 id ( rslt )'''

implementation:
if ( 'mode' in kwargs ) :
    mode = kwargs [ 'mode' ]
else :
    mode = "new"
length = ol . __len__ ( )
if ( start == None ) :
    start = 0
else :
    pass
if ( end == None ) :
    end = length
else :
    pass
start = uniform_index ( start , length )
end = uniform_index ( end , length )
new = copy . deepcopy ( ol )
for i in range ( start , end ) :
    new [ i ] = value
if ( mode == "new" ) :
    return ( new )
else :
    ol . clear ( )
    ol . extend ( new )
    return ( ol )


signature:
def filter ( ol , test_func , * args , ** kwargs ) :
    '''from elist . elist import *
 def test _ func ( ele , x ) :
 cond = ( ele > x )
 return ( cond )
 ol = [ 1,2,3,4]
 id ( ol )
 new = filter ( ol , test _ func , 3)
 new
 id ( new )
 ol = [ 10,20,30,40]
 id ( ol )
 rslt = filter ( ol , test _ func , 3 , mode = " original " )
 rslt
 id ( rslt )'''

implementation:
if ( 'mode' in kwargs ) :
    mode = kwargs [ 'mode' ]
else :
    mode = "new"
length = ol . __len__ ( )
new = [ ]
cpol = copy . deepcopy ( ol )
for i in range ( 0 , length ) :
    cond = test_func ( cpol [ i ] , * args )
    if ( cond ) :
        new . append ( cpol [ i ] )
    else :
        pass
if ( mode == "new" ) :
    return ( new )
else :
    ol . clear ( )
    ol . extend ( new )
    return ( ol )


signature:
def find_last ( ol , test_func , * args ) :
    '''from elist . elist import *
 def test _ func ( ele , x ) :
 cond = ( ele > x )
 return ( cond )
 ol = [ 1,2,3,4]
 last = find _ last ( ol , test _ func , 3)
 last
 ol = [ 10,20,30,40]
 last = find _ last ( ol , test _ func , 3)
 last'''

implementation:
length = ol . __len__ ( )
for i in range ( length - 1 , - 1 , - 1 ) :
    cond = test_func ( ol [ i ] , * args )
    if ( cond ) :
        return ( { 'index' : i , 'value' : ol [ i ] } )
    else :
        pass
return ( { 'index' : None , 'value' : None } )


signature:
def find_which ( ol , which , test_func , * args ) :
    '''from elist . elist import *
 def test _ func ( ele , x ) :
 cond = ( ele > x )
 return ( cond )
 ol = [ 1,2,3,4,5,6,7]
 last = find _ which ( ol , 0 , test _ func , 3)
 last
 last = find _ which ( ol , 2 , test _ func , 3)
 last'''

implementation:
length = ol . __len__ ( )
seq = - 1
for i in range ( 0 , length ) :
    cond = test_func ( ol [ i ] , * args )
    if ( cond ) :
        seq = seq + 1
        if ( seq == which ) :
            return ( { 'index' : i , 'value' : ol [ i ] } )
        else :
            pass
    else :
        pass
return ( { 'index' : None , 'value' : None } )


signature:
def find_seqs ( ol , seqs , test_func , * args ) :
    '''from elist . elist import *
 def test _ func ( ele , x ) :
 cond = ( ele > x )
 return ( cond )
 ol = [ 1,2,3,4,5,6,7]
 some = find _ seqs ( ol , [ 0,3 ] , test _ func , 3)
 some
 some = find _ some ( ol , [ 0,1,2 ] , test _ func , 3)
 some
 # find _ some is the same as find _ seqs'''

implementation:
rslt = [ ]
seqs = list ( seqs )
length = ol . __len__ ( )
seq = - 1
for i in range ( 0 , length ) :
    cond = test_func ( ol [ i ] , * args )
    if ( cond ) :
        seq = seq + 1
        if ( seq in seqs ) :
            rslt . append ( { 'index' : i , 'value' : ol [ i ] } )
        else :
            pass
    else :
        pass
return ( rslt )


signature:
def find_allnot ( ol , test_func , * args ) :
    '''from elist . elist import *
 from elist . jprint import pobj
 def test _ func ( ele , x ) :
 cond = ( ele > x )
 return ( cond )
 ol = [ 1,2,3,4,5,6,7]
 rslt = find _ allnot ( ol , test _ func , 3)
 pobj ( rslt )'''

implementation:
rslt = [ ]
length = ol . __len__ ( )
for i in range ( 0 , length ) :
    cond = test_func ( ol [ i ] , * args )
    if ( cond ) :
        pass
    else :
        rslt . append ( { 'index' : i , 'value' : ol [ i ] } )
return ( rslt )


signature:
def reduce_left ( ol , callback , initialValue ) :
    '''from elist . elist import *
 def callback ( accumulator , currentValue ) :
 accumulator . append ( currentValue [ 0 ] )
 accumulator . append ( currentValue [ 1 ] )
 return ( accumulator )
 ol = [ ( 1,2 ) , ( " a " , " b " ) , ( " x " , " y " ) ]
 reduce _ left ( ol , callback , [ ] )
 # array _ reduce , reduceLeft , reduce _ left are the same'''

implementation:
length = ol . __len__ ( )
accumulator = initialValue
for i in range ( 0 , length ) :
    accumulator = callback ( accumulator , ol [ i ] )
return ( accumulator )


signature:
def diff_indexes ( l1 , l2 ) :
    '''from elist . elist import *
 l1 = [ 1,2,3,5]
 l2 = [ 0,2,3,4]
 diff _ indexes ( l1 , l2)'''

implementation:
rslt = [ ]
for i in range ( 0 , l1 . __len__ ( ) ) :
    if ( l1 [ i ] != l2 [ i ] ) :
        rslt . append ( i )
return ( rslt )


signature:
def diff_values ( l1 , l2 ) :
    '''from elist . elist import *
 l1 = [ 1,2,3,5]
 l2 = [ 0,2,3,4]
 diff _ values ( l1 , l2)'''

implementation:
rslt = [ ]
for i in range ( 0 , l1 . __len__ ( ) ) :
    if ( l1 [ i ] != l2 [ i ] ) :
        rslt . append ( l1 [ i ] )
return ( rslt )


signature:
def same_indexes ( l1 , l2 ) :
    '''from elist . elist import *
 l1 = [ 1,2,3,5]
 l2 = [ 0,2,3,4]
 same _ indexes ( l1 , l2)'''

implementation:
rslt = [ ]
for i in range ( 0 , l1 . __len__ ( ) ) :
    if ( l1 [ i ] == l2 [ i ] ) :
        rslt . append ( i )
return ( rslt )


signature:
def same_values ( l1 , l2 ) :
    '''from elist . elist import *
 l1 = [ 1,2,3,5]
 l2 = [ 0,2,3,4]
 same _ values ( l1 , l2)'''

implementation:
rslt = [ ]
for i in range ( 0 , l1 . __len__ ( ) ) :
    if ( l1 [ i ] == l2 [ i ] ) :
        rslt . append ( l1 [ i ] )
return ( rslt )


signature:
def value_indexes_mapping ( l ) :
    '''from elist . elist import *
 from elist . jprint import pobj
 l = [ ' a ' , ' b ' , ' b ' , ' a ' , ' c ' , ' b ' ]
 desc = value _ indexes _ mapping ( l )
 pobj ( desc )'''

implementation:
pt = copy . deepcopy ( l )
desc = { }
vset = set ( { } )
for v in pt :
    vset . add ( v )
for v in vset :
    desc [ v ] = [ ]
for i in range ( 0 , l . __len__ ( ) ) :
    desc [ l [ i ] ] . append ( i )
return ( desc )


signature:
def cond_value_indexes_mapping ( l , ** kwargs ) :
    '''from elist . elist import *
 l = [ ( ' BIGipServer ' , ' rd19 ' ) , ( ' TS013d8ed5 ' , ' 0105b6b0 ' ) , ( ' BIGipServer ' , ' rd19 ' ) , ( ' TS013d8ed5 ' , ' 0105b6b0 ' ) , ( ' SID ' , ' 1 ' ) , ( ' SID ' , ' 2 ' ) ]
 def cond _ func ( ele , * args ) :
 cond = ele [ 0]
 return ( cond )
 desc = cond _ value _ indexes _ mapping ( l , cond _ func = cond _ func )
 pobj ( desc )'''

implementation:
cond_func = kwargs [ 'cond_func' ]
if ( 'cond_func_args' in kwargs ) :
    cond_func_args = kwargs [ 'cond_func_args' ]
else :
    cond_func_args = [ ]
if ( 'with_none' in kwargs ) :
    with_none = kwargs [ 'with_none' ]
else :
    with_none = False
desc = { }
for i in range ( 0 , l . __len__ ( ) ) :
    ele = l [ i ]
    cond = cond_func ( ele , * cond_func_args )
    if ( ( cond == None ) & ( not ( with_none ) ) ) :
        pass
    else :
        if ( cond in desc ) :
            desc [ cond ] . append ( i )
        else :
            desc [ cond ] = [ i ]
return ( desc )


signature:
def getitem_via_pathlist ( ol , pathlist ) :
    '''from elist . elist import *
 y = [ ' a ' , [ ' b ' , [ " bb " ] ] , ' c ' ]
 y [ 1 ] [ 1]
 getitem _ via _ pathlist ( y , [ 1,1 ] )'''

implementation:
this = ol
for i in range ( 0 , pathlist . __len__ ( ) ) :
    key = pathlist [ i ]
    this = this . __getitem__ ( key )
return ( this )


signature:
def getitem_via_sibseqs ( ol , * sibseqs ) :
    '''from elist . elist import *
 y = [ ' a ' , [ ' b ' , [ " bb " ] ] , ' c ' ]
 y [ 1 ] [ 1]
 getitem _ via _ sibseqs ( y , 1,1)'''

implementation:
pathlist = list ( sibseqs )
this = ol
for i in range ( 0 , pathlist . __len__ ( ) ) :
    key = pathlist [ i ]
    this = this . __getitem__ ( key )
return ( this )


signature:
def setitem_via_pathlist ( ol , value , pathlist ) :
    '''from elist . elist import *
 y = [ ' a ' , [ ' b ' , [ " bb " ] ] , ' c ' ]
 y [ 1 ] [ 1]
 setitem _ via _ pathlist ( y , " 500 " , [ 1,1 ] )'''

implementation:
this = ol
for i in range ( 0 , pathlist . __len__ ( ) - 1 ) :
    key = pathlist [ i ]
    this = this . __getitem__ ( key )
this . __setitem__ ( pathlist [ - 1 ] , value )
return ( ol )


signature:
def setitem_via_sibseqs ( ol , value , * sibseqs ) :
    '''from elist . elist import *
 y = [ ' a ' , [ ' b ' , [ " bb " ] ] , ' c ' ]
 y [ 1 ] [ 1]
 setitem _ via _ sibseqs ( y , " 500 " , 1,1)'''

implementation:
this = ol
pathlist = list ( sibseqs )
for i in range ( 0 , pathlist . __len__ ( ) - 1 ) :
    key = pathlist [ i ]
    this = this . __getitem__ ( key )
this . __setitem__ ( pathlist [ - 1 ] , value )
return ( ol )


signature:
def delitem_via_pathlist ( ol , pathlist ) :
    '''from elist . elist import *
 y = [ ' a ' , [ ' b ' , [ " bb " ] ] , ' c ' ]
 y [ 1 ] [ 1]
 delitem _ via _ pathlist ( y , [ 1,1 ] )'''

implementation:
this = ol
for i in range ( 0 , pathlist . __len__ ( ) - 1 ) :
    key = pathlist [ i ]
    this = this . __getitem__ ( key )
this . __delitem__ ( pathlist [ - 1 ] )
return ( ol )


signature:
def delitem_via_sibseqs ( ol , * sibseqs ) :
    '''from elist . elist import *
 y = [ ' a ' , [ ' b ' , [ " bb " ] ] , ' c ' ]
 y [ 1 ] [ 1]
 delitem _ via _ sibseqs ( y , 1,1)'''

implementation:
pathlist = list ( sibseqs )
this = ol
for i in range ( 0 , pathlist . __len__ ( ) - 1 ) :
    key = pathlist [ i ]
    this = this . __getitem__ ( key )
this . __delitem__ ( pathlist [ - 1 ] )
return ( ol )


signature:
def replace_seqs ( ol , value , indexes , ** kwargs ) :
    '''from elist . elist import *
 ol = [ 1 , ' a ' , 3 , ' a ' , 5 , ' a ' , 6 , ' a ' ]
 id ( ol )
 new = replace _ seqs ( ol , ' AAA ' , [ 1,3,7 ] )
 ol
 new
 id ( ol )
 id ( new )
 ol = [ 1 , ' a ' , 3 , ' a ' , 5 , ' a ' , 6 , ' a ' ]
 id ( ol )
 rslt = replace _ seqs ( ol , ' AAA ' , [ 1,3,7 ] , mode = " original " )
 ol
 rslt
 id ( ol )
 id ( rslt )
 # replace _ indexes = replace _ seqs'''

implementation:
if ( 'mode' in kwargs ) :
    mode = kwargs [ "mode" ]
else :
    mode = "new"
indexes = list ( indexes )
new = [ ]
length = ol . __len__ ( )
cpol = copy . deepcopy ( ol )
for i in range ( 0 , length ) :
    if ( i in indexes ) :
        new . append ( value )
    else :
        new . append ( cpol [ i ] )
if ( mode == "new" ) :
    return ( new )
else :
    ol . clear ( )
    ol . extend ( new )
    return ( ol )


signature:
def replace_some ( ol , value , * indexes , ** kwargs ) :
    '''from elist . elist import *
 ol = [ 1 , ' a ' , 3 , ' a ' , 5 , ' a ' , 6 , ' a ' ]
 id ( ol )
 new = replace _ some ( ol , ' AAA ' , 1,3,7)
 ol
 new
 id ( ol )
 id ( new )
 ol = [ 1 , ' a ' , 3 , ' a ' , 5 , ' a ' , 6 , ' a ' ]
 id ( ol )
 rslt = replace _ some ( ol , ' AAA ' , 1,3,7 , mode = " original " )
 ol
 rslt
 id ( ol )
 id ( rslt )'''

implementation:
if ( 'mode' in kwargs ) :
    mode = kwargs [ "mode" ]
else :
    mode = "new"
indexes = list ( indexes )
return ( replace_seqs ( ol , value , indexes , mode = mode ) )


signature:
def replace_value_seqs ( ol , src_value , dst_value , seqs , ** kwargs ) :
    '''from elist . elist import *
 ol = [ 1 , ' a ' , 3 , ' a ' , 5 , ' a ' , 6 , ' a ' ]
 id ( ol )
 new = replace _ value _ seqs ( ol , ' a ' , ' AAA ' , [ 0,1 ] )
 ol
 new
 id ( ol )
 id ( new )
 ol = [ 1 , ' a ' , 3 , ' a ' , 5 , ' a ' , 6 , ' a ' ]
 id ( ol )
 rslt = replace _ value _ seqs ( ol , ' a ' , ' AAA ' , [ 0,1 ] , mode = " original " )
 ol
 rslt
 id ( ol )
 id ( rslt )'''

implementation:
if ( 'mode' in kwargs ) :
    mode = kwargs [ "mode" ]
else :
    mode = "new"
indexes = indexes_seqs ( ol , src_value , seqs )
return ( replace_indexes ( ol , dst_value , indexes , mode = mode ) )


signature:
def replace_value_some ( ol , src_value , dst_value , * seqs , ** kwargs ) :
    '''from elist . elist import *
 ol = [ 1 , ' a ' , 3 , ' a ' , 5 , ' a ' , 6 , ' a ' ]
 id ( ol )
 new = replace _ value _ some ( ol , ' a ' , ' AAA ' , 0,1)
 ol
 new
 id ( ol )
 id ( new )
 ol = [ 1 , ' a ' , 3 , ' a ' , 5 , ' a ' , 6 , ' a ' ]
 id ( ol )
 rslt = replace _ value _ some ( ol , ' a ' , ' AAA ' , 0,1 , mode = " original " )
 ol
 rslt
 id ( ol )
 id ( rslt )'''

implementation:
if ( 'mode' in kwargs ) :
    mode = kwargs [ "mode" ]
else :
    mode = "new"
return ( replace_value_seqs ( ol , src_value , dst_value , list ( seqs ) , mode = mode ) )


signature:
def cond_replace_value_some ( ol , dst_value , * some , ** kwargs ) :
    '''from elist . elist import *
 ol = [ 1 , ' X ' , 3 , ' b ' , 5 , ' c ' , 6 , ' A ' , 7 , ' b ' , 8 , ' B ' , 9]
 id ( ol )
 def afterCH ( ele , ch ) :
 cond = ( ord ( str ( ele ) ) > ord ( ch ) )
 return ( cond )
 new = cond _ replace _ value _ some ( ol , " REPLACED " , 0,2 , cond _ func = afterCH , cond _ func _ args = [ ' B ' ] )
 ol
 new
 id ( ol )
 id ( new )
 ol = [ 1 , ' X ' , 3 , ' b ' , 5 , ' c ' , 6 , ' A ' , 7 , ' b ' , 8 , ' B ' , 9]
 id ( ol )
 rslt = cond _ replace _ value _ some ( ol , " REPLACED " , 0,2 , cond _ func = afterCH , cond _ func _ args = [ ' B ' ] , mode = " original " )
 ol
 rslt
 id ( ol )
 id ( rslt )'''

implementation:
cond_func = kwargs [ 'cond_func' ]
if ( 'cond_func_args' in kwargs ) :
    cond_func_args = kwargs [ 'cond_func_args' ]
else :
    cond_func_args = [ ]
if ( 'mode' in kwargs ) :
    mode = kwargs [ "mode" ]
else :
    mode = "new"
seqs = list ( some )
new = copy . deepcopy ( ol )
selected = find_all ( new , cond_func , * cond_func_args )
selected_indexes = array_map ( selected , lambda ele : ele [ 'index' ] )
selected_indexes = select_seqs ( selected_indexes , seqs )
new = replace_seqs ( new , dst_value , selected_indexes )
if ( mode == "new" ) :
    return ( new )
else :
    ol . clear ( )
    ol . extend ( new )
    return ( ol )


signature:
def rangize ( break_points , length ) :
    '''break _ points = [ 1,3,9,12 , - 2]
 length = 15
 secs = rangize ( break _ points , length )
 forEach ( secs , print )'''

implementation:
bps = array_map ( break_points , uniform_index , length )
bps . sort ( )
bps = prepend ( bps , 0 )
bps = append ( bps , length )
bps = uniqualize ( bps )
bpslen = bps . __len__ ( )
secs = [ ( 0 , bps [ 0 ] ) ]
for i in range ( 0 , bpslen - 1 ) :
    r = ( bps [ i ] , bps [ i + 1 ] )
    secs . append ( r )
secs . append ( ( bps [ bpslen - 1 ] , length ) )
if ( secs [ 0 ] [ 0 ] == secs [ 0 ] [ 1 ] ) :
    secs . pop ( 0 )
else :
    pass
if ( secs [ - 1 ] [ 0 ] == secs [ - 1 ] [ 1 ] ) :
    secs . pop ( - 1 )
else :
    pass
return ( secs )


implementation:
rslt = [ ]
si = 0
ei = spans [ 0 ] [ 0 ]
if ( si == ei ) :
    pass
else :
    rslt . append ( ( si , ei ) )
prev_ei = spans [ 0 ] [ 1 ]
for i in range ( 1 , spans . __len__ ( ) ) :
    si = prev_ei
    ei = spans [ i ] [ 0 ]
    rslt . append ( ( si , ei ) )
    prev_ei = spans [ i ] [ 1 ]
if ( prev_ei < lngth ) :
    rslt . append ( ( prev_ei , lngth ) )
else :
    rslt . append ( ( prev_ei , lngth + 1 ) )
return ( rslt )


implementation:
T = ( type ( ol [ 0 ] ) == type ( 0 ) )
if ( T ) :
    l = ol
else :
    l = array_map ( ol , ord )
length = l . __len__ ( )
secs = [ ]
si = 0
ei = 0
prev = l [ 0 ]
for i in range ( 1 , length ) :
    curr = l [ i ]
    cond = ( curr == ( prev + 1 ) )
    if ( cond ) :
        ei = i
        prev = curr
    else :
        if ( T ) :
            sec = ( l [ si ] , l [ ei ] )
        else :
            sec = ( ol [ si ] , ol [ ei ] )
        if ( si == ei ) :
            sec = sec [ 0 ]
        else :
            pass
        secs . append ( sec )
        si = i
        ei = i
        prev = curr
if ( T ) :
    sec = ( l [ si ] , l [ ei ] )
else :
    sec = ( ol [ si ] , ol [ ei ] )
if ( si == ei ) :
    sec = sec [ 0 ]
else :
    pass
secs . append ( sec )
return ( secs )


signature:
def range_decompress ( cl ) :
    '''# only support sorted - ints or sorted - ascii
 cl = [ 1 , ( 5 , 8 ) , ( 13 , 14 ) , 18 , ( 30 , 34 ) ]
 range _ decompress ( cl )
 cl = [ 1 , ( 5 , 8 ) , ( 13 , 14 ) , 18 , ( 30 , 34 ) , 40]
 range _ decompress ( cl )
 cl = [ ( ' a ' , ' d ' ) , ( ' j ' , ' n ' ) , ' u ' , ( ' y ' , ' z ' ) ]
 range _ decompress ( cl )'''

implementation:
def cond_func ( ele ) :
    length = ele . __len__ ( )
    cond = ( length == 1 )
    if ( cond ) :
        return ( ord ( ele ) )
    else :
        x = ord ( ele [ 0 ] )
        y = ord ( ele [ 1 ] )
        return ( ( x , y ) )
if ( type ( cl [ 0 ] ) == type ( 0 ) ) :
    T = True
elif ( cl [ 0 ] . __len__ ( ) == 1 ) :
    T = ( type ( cl [ 0 ] ) == type ( 0 ) )
else :
    T = ( type ( cl [ 0 ] [ 0 ] ) == type ( 0 ) )
if ( T ) :
    l = cl
else :
    l = array_map ( cl , cond_func )
rslt = [ ]
for i in range ( 0 , l . __len__ ( ) ) :
    ele = l [ i ]
    if ( type ( ele ) == type ( 0 ) ) :
        arr = [ ele ]
    elif ( ele . __len__ ( ) == 1 ) :
        arr = [ ele ]
    else :
        sv = ele [ 0 ]
        ev = ele [ 1 ]
        arr = init_range ( sv , ev + 1 , 1 )
    if ( T ) :
        pass
    else :
        arr = array_map ( arr , chr )
    rslt . extend ( arr )
return ( rslt )


signature:
def broken_seqs ( ol , break_points ) :
    '''ol = initRange ( 0,20,1)
 ol
 break _ points = [ 1,6,14,9]
 secs = broken _ seqs ( ol , break _ points )
 forEach ( secs , print )'''

implementation:
bps = list ( break_points )
length = ol . __len__ ( )
rgs = rangize ( bps , length )
rslt = [ ]
for i in range ( 0 , rgs . __len__ ( ) ) :
    si , ei = rgs [ i ]
    sec = ol [ si : ei ]
    rslt . append ( sec )
return ( rslt )


implementation:
lngth = arr . __len__ ( )
brkseqs1 = init_range ( 0 , lngth , interval )
brkseqs2 = init_range ( sub_pos , lngth , interval )
brkseqs = interleave ( brkseqs1 , brkseqs2 )
l = broken_seqs ( arr , brkseqs )
kl = select_evens ( l )
vl = select_odds ( l )
if ( "single_key" in kwargs ) :
    single_key = kwargs [ 'single_key' ]
else :
    single_key = True
if ( sub_pos == 1 ) :
    if ( single_key ) :
        kl = mapv ( kl , lambda ele : ele [ 0 ] )
    else :
        pass
else :
    pass
return ( ( kl , vl ) )


signature:
def divide ( ol , interval ) :
    '''ol = elel . initRange ( 0,20,1)
 interval = 3
 rslt = elel . divide ( ol , interval )
 rslt
 rslt = elel . divide ( ol , 4)
 rslt'''

implementation:
length = ol . __len__ ( )
seqs = initRange ( 0 , length , interval )
rslt = broken_seqs ( ol , seqs )
return ( rslt )


signature:
def split ( ol , value , ** kwargs ) :
    '''ol = [ ' a ' , 1 , ' a ' , 2 , ' a ' , 3 , ' a ' , 4 , ' a ' ]
 split ( ol , ' a ' )
 split ( ol , ' a ' , whiches = [ 0 ] )
 split ( ol , ' a ' , whiches = [ 1 ] )
 split ( ol , ' a ' , whiches = [ 2 ] )
 split ( ol , ' a ' , whiches = [ 0,2 ] )
 ol = [ 1 , ' a ' , 2 , ' a ' , 3 , ' a ' , 4]
 split ( ol , ' a ' )
 split ( ' x = bcdsef = g ' , ' = ' , whiches = [ 0 ] )'''

implementation:
if ( 'whiches' in kwargs ) :
    whiches = kwargs [ 'whiches' ]
else :
    whiches = None
indexes = indexes_all ( ol , value )
if ( whiches == None ) :
    pass
else :
    indexes = select_indexes ( indexes , whiches )
rslt = [ ]
rslt . append ( ol [ : indexes [ 0 ] ] )
si = indexes [ 0 ] + 1
for i in range ( 1 , indexes . __len__ ( ) ) :
    ei = indexes [ i ]
    ele = ol [ si : ei ]
    rslt . append ( ele )
    si = ei + 1
ele = ol [ si : ol . __len__ ( ) ]
rslt . append ( ele )
return ( rslt )


signature:
def where ( ol , value ) :
    '''ol = [ 0 , 4 , 6 , 8 , 10 , 14]
 where ( ol , - 1)
 where ( ol , 1)
 where ( ol , 2)
 where ( ol , 3)
 where ( ol , 4)
 where ( ol , 9)
 where ( ol , 14)
 where ( ol , 17)'''

implementation:
si = None
ei = None
for i in range ( 0 , ol . __len__ ( ) ) :
    ele = ol [ i ]
    if ( value > ele ) :
        si = i
    elif ( value == ele ) :
        return ( ( i , i ) )
    else :
        ei = i
        return ( ( si , ei ) )
return ( ( si , ei ) )


signature:
def value_interval ( ol , value ) :
    '''ol = [ 0 , 4 , 6 , 8 , 10 , 14]
 value _ interval ( ol , - 1)
 value _ interval ( ol , 1)
 value _ interval ( ol , 2)
 value _ interval ( ol , 3)
 value _ interval ( ol , 4)
 value _ interval ( ol , 9)
 value _ interval ( ol , 14)
 value _ interval ( ol , 17)'''

implementation:
si , ei = where ( ol , value )
if ( si == None ) :
    sv = None
else :
    sv = ol [ si ]
if ( ei == None ) :
    ev = None
else :
    ev = ol [ ei ]
return ( ( sv , ev ) )


signature:
def rand_sub ( arr , * args , ** kwargs ) :
    '''arr = [ ' scheme ' , ' username ' , ' password ' , ' hostname ' , ' port ' , ' path ' , ' params ' , ' query ' , ' fragment ' ]
 rand _ sub ( arr , 3)
 rand _ sub ( arr , 3)
 rand _ sub ( arr , 3)
 rand _ sub ( arr )
 rand _ sub ( arr )
 rand _ sub ( arr )'''

implementation:
arr = copy . deepcopy ( arr )
lngth = arr . __len__ ( )
args = list ( args )
if ( args . __len__ ( ) == 0 ) :
    n = random . randrange ( 0 , lngth )
else :
    n = args [ 0 ]
    if ( n > lngth ) :
        n = lngth
    else :
        pass
indexes = rand_some_indexes ( 0 , lngth , n , ** kwargs )
narr = select_seqs_keep_order ( arr , indexes )
return ( narr )


signature:
def is_leaf ( obj ) :
    '''the below is for nested - list
 any type is not list will be treated as a leaf
 empty list will be treated as a leaf
 from elist . elist import *
 is _ leaf ( 1)
 is _ leaf ( [ 1,2,3 ] )
 is _ leaf ( [ ] )'''

implementation:
if ( is_list ( obj ) ) :
    length = obj . __len__ ( )
    if ( length == 0 ) :
        return ( True )
    else :
        return ( False )
else :
    return ( True )


signature:
def new_ele_description ( ** kwargs ) :
    '''from elist . elist import *
 from elist . jprint import pobj
 root _ desc = new _ ele _ description ( leaf = False , depth = 0 , breadth _ path = [ ] , path = [ ] , parent _ path = [ ] , parent _ breadth _ path = [ ] )
 pobj ( root _ desc )
 # None means not handled'''

implementation:
desc = { 'leaf' : None , 'depth' : None , 'breadth' : None , 'breadth_path' : None , 'sib_seq' : None , 'path' : None , 'parent_path' : None , 'parent_breadth_path' : None , 'lsib_path' : None , 'rsib_path' : None , 'lcin_path' : None , 'rcin_path' : None , 'sons_count' : None , 'leaf_son_paths' : None , 'non_leaf_son_paths' : None , 'leaf_descendant_paths' : None , 'non_leaf_descendant_paths' : None , 'flat_offset' : None , 'flat_len' : None }
for key in kwargs :
    desc [ key . lower ( ) ] = kwargs [ key ]
return ( desc )


signature:
def init_desc_matrix ( l ) :
    '''from elist . elist import *
 from elist . jprint import pobj
 l = [ 1 , [ 4 ] , 2 , [ 3 , [ 5,6 ] ] ]
 desc _ matrix = init _ desc _ matrix ( l )
 pobj ( desc _ matrix )'''

implementation:
leaf = is_leaf ( l )
root_desc = new_ele_description ( leaf = leaf , depth = 0 , breadth_path = [ ] , path = [ ] , parent_path = [ ] , parent_breadth_path = [ ] )
if ( leaf ) :
    root_desc [ 'sons_count' ] = 0
else :
    pass
desc_matrix = [ [ root_desc ] ]
return ( desc_matrix )


signature:
def _init_unhandled ( l , inited_matrix ) :
    '''from elist . elist import *
 from elist . jprint import pobj
 l = [ 1 , [ 4 ] , 2 , [ 3 , [ 5,6 ] ] ]
 desc _ matrix = init _ desc _ matrix ( l )
 unhandled = _ init _ unhandled ( l , desc _ matrix )
 unhandled _ data = unhandled [ ' data ' ]
 unhandled _ desc = unhandled [ ' desc ' ]
 unhandled _ data [ 0]
 unhandled _ desc [ 0]
 unhandled _ data [ 1]
 unhandled _ desc [ 1]'''

implementation:
root_desc = inited_matrix [ 0 ] [ 0 ]
unhandled = { 'data' : [ ] , 'desc' : [ ] }
length = l . __len__ ( )
root_desc [ 'sons_count' ] = length
root_desc [ 'leaf_son_paths' ] = [ ]
root_desc [ 'non_leaf_son_paths' ] = [ ]
if ( length == 0 ) :
    pass
else :
    inited_matrix . append ( [ ] )
    level = inited_matrix [ 1 ]
    for i in range ( 0 , length ) :
        child = l [ i ]
        desc = copy . deepcopy ( root_desc )
        desc = reset_parent_desc_template ( desc )
        desc [ 'depth' ] = 1
        desc [ 'breadth' ] = i
        desc [ 'parent_breadth_path' ] = copy . deepcopy ( desc [ 'breadth_path' ] )
        desc [ 'breadth_path' ] . append ( i )
        desc [ 'sib_seq' ] = i
        desc [ 'parent_path' ] = copy . deepcopy ( desc [ 'path' ] )
        desc [ 'path' ] . append ( i )
        if ( i == 0 ) :
            pass
        else :
            desc [ 'lsib_path' ] = [ i - 1 ]
        if ( i == ( length - 1 ) ) :
            pass
        else :
            desc [ 'rsib_path' ] = [ i + 1 ]
        if ( is_leaf ( child ) ) :
            desc [ 'leaf' ] = True
            desc [ 'sons_count' ] = 0
            root_desc [ 'leaf_son_paths' ] . append ( copy . deepcopy ( desc [ 'path' ] ) )
        else :
            desc [ 'leaf' ] = False
            root_desc [ 'non_leaf_son_paths' ] . append ( copy . deepcopy ( desc [ 'path' ] ) )
            unhandled [ 'data' ] . append ( child )
            unhandled [ 'desc' ] . append ( desc )
        level . append ( desc )
return ( unhandled )


signature:
def update_desc_lsib_path ( desc ) :
    '''leftSibling
 previousSibling
 leftSib
 prevSib
 lsib
 psib
 have the same parent , and on the left'''

implementation:
if ( desc [ 'sib_seq' ] > 0 ) :
    lsib_path = copy . deepcopy ( desc [ 'path' ] )
    lsib_path [ - 1 ] = desc [ 'sib_seq' ] - 1
    desc [ 'lsib_path' ] = lsib_path
else :
    pass
return ( desc )


signature:
def update_desc_rsib_path ( desc , sibs_len ) :
    '''rightSibling
 nextSibling
 rightSib
 nextSib
 rsib
 nsib
 have the same parent , and on the right'''

implementation:
if ( desc [ 'sib_seq' ] < ( sibs_len - 1 ) ) :
    rsib_path = copy . deepcopy ( desc [ 'path' ] )
    rsib_path [ - 1 ] = desc [ 'sib_seq' ] + 1
    desc [ 'rsib_path' ] = rsib_path
else :
    pass
return ( desc )


signature:
def update_desc_lcin_path ( desc , pdesc_level ) :
    '''leftCousin
 previousCousin
 leftCin
 prevCin
 lcin
 pcin
 parents are neighbors , and on the left'''

implementation:
parent_breadth = desc [ 'parent_breadth_path' ] [ - 1 ]
if ( desc [ 'sib_seq' ] == 0 ) :
    if ( parent_breadth == 0 ) :
        pass
    else :
        parent_lsib_breadth = parent_breadth - 1
        plsib_desc = pdesc_level [ parent_lsib_breadth ]
        if ( plsib_desc [ 'leaf' ] ) :
            pass
        else :
            lcin_path = copy . deepcopy ( plsib_desc [ 'path' ] )
            lcin_path . append ( plsib_desc [ 'sons_count' ] - 1 )
            desc [ 'lcin_path' ] = lcin_path
else :
    pass
return ( desc )


signature:
def update_desc_rcin_path ( desc , sibs_len , pdesc_level ) :
    '''rightCousin
 nextCousin
 rightCin
 nextCin
 rcin
 ncin
 parents are neighbors , and on the right'''

implementation:
psibs_len = pdesc_level . __len__ ( )
parent_breadth = desc [ 'parent_breadth_path' ] [ - 1 ]
if ( desc [ 'sib_seq' ] == ( sibs_len - 1 ) ) :
    if ( parent_breadth == ( psibs_len - 1 ) ) :
        pass
    else :
        parent_rsib_breadth = parent_breadth + 1
        prsib_desc = pdesc_level [ parent_rsib_breadth ]
        # because from left to right to handle each level
        # sons _ count will only be updated in the next - round
        if ( prsib_desc [ 'leaf' ] ) :
            pass
        else :
            rcin_path = copy . deepcopy ( prsib_desc [ 'path' ] )
            rcin_path . append ( 0 )
            desc [ 'rcin_path' ] = rcin_path
else :
    pass
return ( desc )


signature:
def scan ( l , ** kwargs ) :
    '''from elist . elist import *
 from elist . jprint import pobj
 l = [ 1 , [ 4 ] , 2 , [ 3 , [ 5,6 ] ] ]
 desc = description ( l )
 l = [ 1,2 , [ 4 ] , [ 3 , [ 5,6 ] ] ]
 desc = description ( l )'''

implementation:
if ( 'itermode' in kwargs ) :
    itermode = True
else :
    itermode = False
# # # # level = = 0
desc_matrix = init_desc_matrix ( l )
if ( desc_matrix [ 0 ] [ 0 ] [ 'leaf' ] == True ) :
    return ( desc_matrix )
else :
    pass
# # # # cache
lcache = LevelCache ( datas = l , descs = desc_matrix [ 0 ] [ 0 ] )
scache = StateCache ( desc_matrix )
pcache = init_pcache_handler_inline ( kwargs )
# # # # level > 0
while ( lcache . data . __len__ ( ) > 0 ) : # add next desc _ level
    scache . update ( )
    for unhandled_seq in range ( 0 , lcache . data . __len__ ( ) ) : # handle parent
        pcache . update_pdesc ( lcache , unhandled_seq )
        for sib_seq in range ( 0 , pcache . sibs_len ) : # handle child
            pcache . update_desc ( lcache , scache , sib_seq )
    # update level lcache
    lcache . update ( )
return ( desc_matrix )


signature:
def fullfill_descendants_info ( desc_matrix ) :
    '''flat _ offset'''

implementation:
pathloc_mapping = { }
locpath_mapping = { }
# def leaf _ handler ( desc , pdesc , offset ) :
def leaf_handler ( desc , pdesc ) : # desc [ ' flat _ offset ' ] = ( offset , offset + 1)
    desc [ 'non_leaf_son_paths' ] = [ ]
    desc [ 'leaf_son_paths' ] = [ ]
    desc [ 'non_leaf_descendant_paths' ] = [ ]
    desc [ 'leaf_descendant_paths' ] = [ ]
    desc [ 'flat_len' ] = 1
    if ( pdesc [ 'flat_len' ] ) :
        pdesc [ 'flat_len' ] = pdesc [ 'flat_len' ] + 1
    else :
        pdesc [ 'flat_len' ] = 1
# def non _ leaf _ handler ( desc , pdesc , offset ) :
def non_leaf_handler ( desc , pdesc ) : # desc [ ' flat _ offset ' ] = ( offset , offset + desc [ ' flat _ len ' ] )
    pdesc [ 'non_leaf_descendant_paths' ] . extend ( copy . deepcopy ( desc [ 'non_leaf_descendant_paths' ] ) )
    pdesc [ 'leaf_descendant_paths' ] . extend ( copy . deepcopy ( desc [ 'leaf_descendant_paths' ] ) )
    if ( pdesc [ 'flat_len' ] ) :
        pdesc [ 'flat_len' ] = pdesc [ 'flat_len' ] + desc [ 'flat_len' ]
    else :
        pdesc [ 'flat_len' ] = desc [ 'flat_len' ]
def fill_path_mapping ( desc ) :
    pmk = tuple ( desc [ 'path' ] )
    pmv = tuple ( DescMatrix . loc ( desc ) )
    pathloc_mapping [ pmk ] = pmv
    locpath_mapping [ pmv ] = pmk
dm = DescMatrix ( desc_matrix )
depth = desc_matrix . __len__ ( )
desc_level = desc_matrix [ depth - 1 ]
length = desc_level . __len__ ( )
# the last level
# offset = 0
for j in range ( length - 1 , - 1 , - 1 ) :
    desc = desc_level [ j ]
    fill_path_mapping ( desc )
    pdesc = dm . pdesc ( desc )
    leaf_handler ( desc , pdesc )
    # leaf _ handler ( desc , pdesc , offset )
    # offset = offset + 1
for i in range ( depth - 2 , 0 , - 1 ) : # offset = 0
    desc_level = desc_matrix [ i ]
    length = desc_level . __len__ ( )
    for j in range ( length - 1 , - 1 , - 1 ) :
        desc = desc_level [ j ]
        fill_path_mapping ( desc )
        pdesc = dm . pdesc ( desc )
        if ( desc [ 'leaf' ] ) :
            leaf_handler ( desc , pdesc )
            # leaf _ handler ( desc , pdesc , offset )
            # offset = offset + 1
        else :
            non_leaf_handler ( desc , pdesc )
            # non _ leaf _ handler ( desc , pdesc , offset )
            # offset = offset + desc [ ' flat _ len ' ]
desc_matrix [ 0 ] [ 0 ] [ 'flat_offset' ] = ( 0 , desc_matrix [ 0 ] [ 0 ] [ 'flat_len' ] )
for i in range ( 0 , depth - 1 ) :
    pdesc_level = desc_matrix [ i ]
    length = pdesc_level . __len__ ( )
    for j in range ( 0 , length ) :
        pdesc = pdesc_level [ j ]
        si = pdesc [ 'flat_offset' ] [ 0 ]
        for i in range ( 0 , pdesc [ 'sons_count' ] ) :
            spl = append ( pdesc [ 'path' ] , i , mode = 'new' )
            pk = tuple ( spl )
            locx , locy = pathloc_mapping [ pk ]
            son = desc_matrix [ locx ] [ locy ]
            ei = si + son [ 'flat_len' ]
            son [ 'flat_offset' ] = ( si , ei )
            si = ei
return ( desc_matrix , pathloc_mapping , locpath_mapping )


signature:
def pathlist_to_getStr ( path_list ) :
    '''> > > pathlist _ to _ getStr ( [ 1 , ' 1 ' , 2 ] )
 " [ 1 ] [ ' 1 ' ] [ 2 ] "'''


signature:
def getStr_to_pathlist ( gs ) :
    '''gs = " [ 1 ] [ ' 1 ' ] [ 2 ] "
 getStr _ to _ pathlist ( gs )
 gs = " [ ' u ' ] [ ' u1 ' ] "
 getStr _ to _ pathlist ( gs )'''

implementation:
def numize ( w ) :
    try :
        int ( w )
    except :
        try :
            float ( w )
        except :
            return ( w )
        else :
            return ( float ( w ) )
    else :
        return ( int ( w ) )
def strip_quote ( w ) :
    if ( type ( w ) == type ( '' ) ) :
        if ( w [ 0 ] == w [ - 1 ] ) :
            if ( ( w [ 0 ] == "'" ) | ( w [ 0 ] == '"' ) ) :
                return ( w [ 1 : - 1 ] )
            else :
                return ( w )
        else :
            return ( w )
    else :
        return ( w )
gs = gs [ 1 : - 1 ]
pl = gs . split ( "][" )
pl = array_map ( pl , numize )
pl = array_map ( pl , strip_quote )
return ( pl )


implementation:
pairs_str_len = pairs_str . __len__ ( )
pairs_len = pairs_str_len // 2
pairs_dict = { }
for i in range ( 1 , pairs_len + 1 ) :
    pairs_dict [ i ] = pairs_str [ i * 2 - 2 ] , pairs_str [ i * 2 - 1 ]
return ( pairs_dict )


signature:
def is_lop ( ch , block_op_pairs_dict = get_block_op_pairs ( '{}[]()' ) ) :
    '''# is _ lop ( ' { ' , block _ op _ pairs _ dict )
 # is _ lop ( ' [ ' , block _ op _ pairs _ dict )
 # is _ lop ( ' } ' , block _ op _ pairs _ dict )
 # is _ lop ( ' ] ' , block _ op _ pairs _ dict )
 # is _ lop ( ' a ' , block _ op _ pairs _ dict )'''

implementation:
for i in range ( 1 , block_op_pairs_dict . __len__ ( ) + 1 ) :
    if ( ch == block_op_pairs_dict [ i ] [ 0 ] ) :
        return ( True )
    else :
        pass
return ( False )


signature:
def get_next_char_level_in_j_str ( curr_lv , curr_seq , j_str , block_op_pairs_dict = get_block_op_pairs ( "{}[]()" ) ) :
    '''the first - char is level - 1
 when current is non - op , next - char - level = curr - level
 when current is lop , non - paired - rop - next - char - level = lop - level + 1;
 when current is lop , paired - rop - next - char - level = lop - level
 when current is rop , next - char - level = rop - level - 1
 # { " key _ 4 _ UF0aJJ6v " : " value _ 1 " , " key _ 2 _ Hd0t " : [ " value _ 16 " , " value _ 8 " , " value _ 8 " , " value _ 15 " , " value _ 14 " , " value _ 19 " , { . . . . .
 # 122222333334 . . . . .
 # { \n " key _ 4 _ UF0aJJ6v " : " value _ 1 " , \n " key _ 2 _ Hd0t " : [ \n " value _ 16 " , \n " value _ 8 " , \n " value _ 8 " , \n " value _ 15 " , \n " value _ 14 " , \n " value _ 19 " , . . . . .
 # 1 22222 22222 33333 33333 33333 33333 33333 33333 . . . . .'''

implementation:
curr_ch = j_str [ curr_seq ]
next_ch = j_str [ curr_seq + 1 ]
cond = 0
for i in range ( 1 , block_op_pairs_dict . __len__ ( ) + 1 ) :
    if ( curr_ch == block_op_pairs_dict [ i ] [ 0 ] ) :
        if ( next_ch == block_op_pairs_dict [ i ] [ 1 ] ) :
            next_lv = curr_lv
        else :
            next_lv = curr_lv + 1
        cond = 1
        break
    elif ( curr_ch == block_op_pairs_dict [ i ] [ 1 ] ) :
        if ( is_rop ( next_ch , block_op_pairs_dict ) ) :
            next_lv = curr_lv - 1
        else :
            next_lv = curr_lv
        cond = 1
        break
    else :
        pass
if ( cond == 1 ) :
    pass
elif ( is_rop ( next_ch , block_op_pairs_dict ) ) :
    next_lv = curr_lv - 1
else :
    next_lv = curr_lv
curr_lv = next_lv
curr_seq = curr_seq + 1
return ( curr_lv , curr_lv , curr_seq )


signature:
def str_display_width ( s ) :
    '''from elist . utils import *
 str _ display _ width ( ' a ' )
 str _ display _ width ( ' 去 ' )'''

implementation:
s = str ( s )
width = 0
len = s . __len__ ( )
for i in range ( 0 , len ) :
    sublen = s [ i ] . encode ( ) . __len__ ( )
    sublen = int ( sublen / 2 + 1 / 2 )
    width = width + sublen
return ( width )


implementation:
ltree = ListTree ( l )
vdescmat = ltree . desc
wfsmat = matrix_map ( vdescmat , lambda v , ix , iy : v [ 'path' ] )
wfsmat . pop ( 0 )
return ( wfsmat )


implementation:
wfsmat = [ ]
depth = 0
level = filter ( wfs , lambda ele : ele . __len__ ( ) == 1 )
while ( level . __len__ ( ) > 0 ) :
    wfsmat . append ( [ ] )
    wfsmat [ depth ] = level
    depth = depth + 1
    level = filter ( wfs , lambda ele : ele . __len__ ( ) == depth + 1 )
return ( wfsmat )


implementation:
wfsmat = [ ]
depth = 0
level = filter ( dfs , lambda ele : ele . __len__ ( ) == 1 )
while ( level . __len__ ( ) > 0 ) :
    wfsmat . append ( [ ] )
    wfsmat [ depth ] = level
    depth = depth + 1
    level = filter ( dfs , lambda ele : ele . __len__ ( ) == depth + 1 )
return ( wfsmat )


signature:
def parent_handler ( self , lcache , i , * args ) :
    '''_ update _ pdesc _ sons _ info'''

implementation:
pdesc = lcache . desc [ i ]
pdesc [ 'sons_count' ] = self . sibs_len
pdesc [ 'leaf_son_paths' ] = [ ]
pdesc [ 'non_leaf_son_paths' ] = [ ]
pdesc [ 'leaf_descendant_paths' ] = [ ]
pdesc [ 'non_leaf_descendant_paths' ] = [ ]
return ( pdesc )


signature:
def child_begin_handler ( self , scache , * args ) :
    '''_ creat _ child _ desc
 update depth , parent _ breadth _ path , parent _ path , sib _ seq , path , lsib _ path , rsib _ path , lcin _ path , rcin _ path'''

implementation:
pdesc = self . pdesc
depth = scache . depth
sib_seq = self . sib_seq
sibs_len = self . sibs_len
pdesc_level = scache . pdesc_level
desc = copy . deepcopy ( pdesc )
desc = reset_parent_desc_template ( desc )
desc [ 'depth' ] = depth
desc [ 'parent_breadth_path' ] = copy . deepcopy ( desc [ 'breadth_path' ] )
desc [ 'sib_seq' ] = sib_seq
desc [ 'parent_path' ] = copy . deepcopy ( desc [ 'path' ] )
desc [ 'path' ] . append ( sib_seq )
update_desc_lsib_path ( desc )
update_desc_rsib_path ( desc , sibs_len )
if ( depth == 1 ) :
    pass
else :
    update_desc_lcin_path ( desc , pdesc_level )
    update_desc_rcin_path ( desc , sibs_len , pdesc_level )
return ( desc )


signature:
def leaf_handler ( self , * args ) :
    '''# leaf child handler'''

implementation:
desc = self . desc
pdesc = self . pdesc
desc [ 'leaf' ] = True
desc [ 'sons_count' ] = 0
pdesc [ 'leaf_son_paths' ] . append ( copy . deepcopy ( desc [ 'path' ] ) )
pdesc [ 'leaf_descendant_paths' ] . append ( copy . deepcopy ( desc [ 'path' ] ) )


signature:
def non_leaf_handler ( self , lcache ) :
    '''# nonleaf child handler'''

implementation:
desc = self . desc
pdesc = self . pdesc
desc [ 'leaf' ] = False
pdesc [ 'non_leaf_son_paths' ] . append ( copy . deepcopy ( desc [ 'path' ] ) )
pdesc [ 'non_leaf_descendant_paths' ] . append ( copy . deepcopy ( desc [ 'path' ] ) )
lcache . ndata . append ( self . data )
lcache . ndesc . append ( desc )


signature:
def child_end_handler ( self , scache ) :
    '''_ upgrade _ breadth _ info
 update breadth , breadth _ path , and add desc to desc _ level'''

implementation:
desc = self . desc
desc_level = scache . desc_level
breadth = desc_level . __len__ ( )
desc [ 'breadth' ] = breadth
desc [ 'breadth_path' ] . append ( breadth )
desc_level . append ( desc )


signature:
def parse ( self , source ) :
    """Parse command content from the LaTeX source .
 Parameters
 source : ` str `
 The full source of the tex document .
 Yields
 parsed _ command : ` ParsedCommand `
 Yields parsed commands instances for each occurence of the command
 in the source ."""

implementation:
command_regex = self . _make_command_regex ( self . name )
for match in re . finditer ( command_regex , source ) :
    self . _logger . debug ( match )
    start_index = match . start ( 0 )
    yield self . _parse_command ( source , start_index )


signature:
def _parse_command ( self , source , start_index ) :
    """Parse a single command .
 Parameters
 source : ` str `
 The full source of the tex document .
 start _ index : ` int `
 Character index in ` ` source ` ` where the command begins .
 Returns
 parsed _ command : ` ParsedCommand `
 The parsed command from the source at the given index ."""

implementation:
parsed_elements = [ ]
# Index of the parser in the source
running_index = start_index
for element in self . elements :
    opening_bracket = element [ 'bracket' ]
    closing_bracket = self . _brackets [ opening_bracket ]
    # Find the opening bracket .
    element_start = None
    element_end = None
    for i , c in enumerate ( source [ running_index : ] , start = running_index ) :
        if c == element [ 'bracket' ] :
            element_start = i
            break
        elif c == '\n' : # No starting bracket on the line .
            if element [ 'required' ] is True : # Try to parse a single single - word token after the
            # command , like ' \ input file '
                content = self . _parse_whitespace_argument ( source [ running_index : ] , self . name )
                return ParsedCommand ( self . name , [ { 'index' : element [ 'index' ] , 'name' : element [ 'name' ] , 'content' : content . strip ( ) } ] , start_index , source [ start_index : i ] )
            else : # Give up on finding an optional element
                break
    # Handle cases when the opening bracket is never found .
    if element_start is None and element [ 'required' ] is False : # Optional element not found . Continue to next element ,
    # not advancing the running _ index of the parser .
        continue
    elif element_start is None and element [ 'required' ] is True :
        message = ( 'Parsing command {0} at index {1:d}, ' 'did not detect element {2:d}' . format ( self . name , start_index , element [ 'index' ] ) )
        raise CommandParserError ( message )
    # Find the closing bracket , keeping track of the number of times
    # the same type of bracket was opened and closed .
    balance = 1
    for i , c in enumerate ( source [ element_start + 1 : ] , start = element_start + 1 ) :
        if c == opening_bracket :
            balance += 1
        elif c == closing_bracket :
            balance -= 1
        if balance == 0 :
            element_end = i
            break
    if balance > 0 :
        message = ( 'Parsing command {0} at index {1:d}, ' 'did not find closing bracket for required ' 'command element {2:d}' . format ( self . name , start_index , element [ 'index' ] ) )
        raise CommandParserError ( message )
    # Package the parsed element ' s content .
    element_content = source [ element_start + 1 : element_end ]
    parsed_element = { 'index' : element [ 'index' ] , 'name' : element [ 'name' ] , 'content' : element_content . strip ( ) }
    parsed_elements . append ( parsed_element )
    running_index = element_end + 1
command_source = source [ start_index : running_index ]
parsed_command = ParsedCommand ( self . name , parsed_elements , start_index , command_source )
return parsed_command


signature:
def _parse_whitespace_argument ( source , name ) :
    r"""Attempt to parse a single token on the first line of this source .
 This method is used for parsing whitespace - delimited arguments , like
 ` ` \ input file ` ` . The source should ideally contain ` ` file ` ` along
 with a newline character .
 > > > source = ' Line 1 \ n ' r ' \ input test . tex ' ' \ nLine 2'
 > > > LatexCommand . _ parse _ whitespace _ argument ( source , ' input ' )
 ' test . tex '
 Bracket delimited arguments ( ` ` \ input { test . tex } ` ` ) are handled in
 the normal logic of ` _ parse _ command ` ."""

implementation:
# First match the command name itself so that we find the argument
# * after * the command
command_pattern = r'\\(' + name + r')(?:[\s{[%])'
command_match = re . search ( command_pattern , source )
if command_match is not None : # Trim ` source ` so we only look after the command
    source = source [ command_match . end ( 1 ) : ]
# Find the whitespace - delimited argument itself .
pattern = r'(?P<content>\S+)(?:[ %\t\n]+)'
match = re . search ( pattern , source )
if match is None :
    message = ( 'When parsing {}, did not find whitespace-delimited command ' 'argument' )
    raise CommandParserError ( message . format ( name ) )
content = match . group ( 'content' )
content . strip ( )
return content


signature:
def _tmdd_datetime_to_iso ( dt , include_offset = True , include_seconds = True ) :
    """dt is an xml Element with < date > , < time > , and optionally < offset > children .
 returns an ISO8601 string"""

implementation:
datestring = dt . findtext ( 'date' )
timestring = dt . findtext ( 'time' )
assert len ( datestring ) == 8
assert len ( timestring ) >= 6
iso = datestring [ 0 : 4 ] + '-' + datestring [ 4 : 6 ] + '-' + datestring [ 6 : 8 ] + 'T' + timestring [ 0 : 2 ] + ':' + timestring [ 2 : 4 ]
if include_seconds :
    iso += ':' + timestring [ 4 : 6 ]
if include_offset :
    offset = dt . findtext ( 'offset' )
    if offset :
        assert len ( offset ) == 5
        iso += offset [ 0 : 3 ] + ':' + offset [ 3 : 5 ]
    else :
        raise Exception ( "TMDD date is not timezone-aware: %s" % etree . tostring ( dt ) )
return iso


signature:
def _generate_automatic_headline ( c ) :
    """The only field that maps closely to Open511 < headline > , a required field , is optional
 in TMDD . So we sometimes need to generate our own ."""

implementation:
# Start with the event type , e . g . " Incident "
headline = c . data [ 'event_type' ] . replace ( '_' , ' ' ) . title ( )
if c . data [ 'roads' ] : # Add the road name
    headline += ' on ' + c . data [ 'roads' ] [ 0 ] [ 'name' ]
    direction = c . data [ 'roads' ] [ 0 ] . get ( 'direction' )
    if direction and direction not in ( 'BOTH' , 'NONE' ) :
        headline += ' ' + direction
return headline


signature:
def _get_severity ( c ) :
    """1 . Collect all < severity > and < impact - level > values .
 2 . Convert impact - level of 1-3 to MINOR , 4-7 to MODERATE , 8-10 to MAJOR
 3 . Map severity - > none to MINOR , natural - disaster to MAJOR , other to UNKNOWN
 4 . Pick the highest severity ."""

implementation:
severities = c . feu . xpath ( 'event-indicators/event-indicator/event-severity/text()|event-indicators/event-indicator/severity/text()' )
impacts = c . feu . xpath ( 'event-indicators/event-indicator/event-impact/text()|event-indicators/event-indicator/impact/text()' )
severities = [ convert_severity [ s ] for s in severities ]
impacts = [ convert_impact [ i ] for i in impacts ]
return [ 'UNKNOWN' , 'MINOR' , 'MODERATE' , 'MAJOR' ] [ max ( itertools . chain ( severities , impacts ) ) ]


signature:
def list_from_document ( cls , doc ) :
    """Returns a list of TMDDEventConverter elements .
 doc is an XML Element containing one or more < FEU > events"""

implementation:
objs = [ ]
for feu in doc . xpath ( '//FEU' ) :
    detail_els = feu . xpath ( 'event-element-details/event-element-detail' )
    for idx , detail in enumerate ( detail_els ) :
        objs . append ( cls ( feu , detail , id_suffix = idx , number_in_group = len ( detail_els ) ) )
return objs


signature:
def add_geo ( self , geo_location ) :
    """Saves a < geo - location > Element , to be incoporated into the Open511
 geometry field ."""

implementation:
if not geo_location . xpath ( 'latitude' ) and geo_location . xpath ( 'longitude' ) :
    raise Exception ( "Invalid geo-location %s" % etree . tostring ( geo_location ) )
if _xpath_or_none ( geo_location , 'horizontal-datum/text()' ) not in ( 'wgs84' , None ) :
    logger . warning ( "Unsupported horizontal-datum in %s" % etree . tostring ( geo_location ) )
    return
point = ( float ( _xpath_or_none ( geo_location , 'longitude/text()' ) ) / 1000000 , float ( _xpath_or_none ( geo_location , 'latitude/text()' ) ) / 1000000 )
self . points . add ( point )


signature:
def clone ( src , dst_path , skip_globals , skip_dimensions , skip_variables ) :
    """Mostly ripped from nc3tonc4 in netCDF4 - python .
 Added ability to skip dimension and variables .
 Removed all of the unpacking logic for shorts ."""

implementation:
if os . path . exists ( dst_path ) :
    os . unlink ( dst_path )
dst = netCDF4 . Dataset ( dst_path , 'w' )
# Global attributes
for attname in src . ncattrs ( ) :
    if attname not in skip_globals :
        setattr ( dst , attname , getattr ( src , attname ) )
# Dimensions
unlimdim = None
unlimdimname = False
for dimname , dim in src . dimensions . items ( ) : # Skip what we need to
    if dimname in skip_dimensions :
        continue
    if dim . isunlimited ( ) :
        unlimdim = dim
        unlimdimname = dimname
        dst . createDimension ( dimname , None )
    else :
        dst . createDimension ( dimname , len ( dim ) )
# Variables
for varname , ncvar in src . variables . items ( ) : # Skip what we need to
    if varname in skip_variables :
        continue
    hasunlimdim = False
    if unlimdimname and unlimdimname in ncvar . dimensions :
        hasunlimdim = True
    filler = None
    if hasattr ( ncvar , '_FillValue' ) :
        filler = ncvar . _FillValue
    if ncvar . chunking == "contiguous" :
        var = dst . createVariable ( varname , ncvar . dtype , ncvar . dimensions , fill_value = filler )
    else :
        var = dst . createVariable ( varname , ncvar . dtype , ncvar . dimensions , fill_value = filler , chunksizes = ncvar . chunking ( ) )
    # Attributes
    for attname in ncvar . ncattrs ( ) :
        if attname == '_FillValue' :
            continue
        else :
            setattr ( var , attname , getattr ( ncvar , attname ) )
    # Data
    nchunk = 1000
    if hasunlimdim :
        if nchunk :
            start = 0
            stop = len ( unlimdim )
            step = nchunk
            if step < 1 :
                step = 1
            for n in range ( start , stop , step ) :
                nmax = n + nchunk
                if nmax > len ( unlimdim ) :
                    nmax = len ( unlimdim )
                idata = ncvar [ n : nmax ]
                var [ n : nmax ] = idata
        else :
            idata = ncvar [ : ]
            var [ 0 : len ( unlimdim ) ] = idata
    else :
        idata = ncvar [ : ]
        var [ : ] = idata
    dst . sync ( )
src . close ( )
dst . close ( )


signature:
def get_dataframe_from_variable ( nc , data_var ) :
    """Returns a Pandas DataFrame of the data .
 This always returns positive down depths"""

implementation:
time_var = nc . get_variables_by_attributes ( standard_name = 'time' ) [ 0 ]
depth_vars = nc . get_variables_by_attributes ( axis = lambda v : v is not None and v . lower ( ) == 'z' )
depth_vars += nc . get_variables_by_attributes ( standard_name = lambda v : v in [ 'height' , 'depth' 'surface_altitude' ] , positive = lambda x : x is not None )
# Find the correct depth variable
depth_var = None
for d in depth_vars :
    try :
        if d . _name in data_var . coordinates . split ( " " ) or d . _name in data_var . dimensions :
            depth_var = d
            break
    except AttributeError :
        continue
times = netCDF4 . num2date ( time_var [ : ] , units = time_var . units , calendar = getattr ( time_var , 'calendar' , 'standard' ) )
original_times_size = times . size
if depth_var is None and hasattr ( data_var , 'sensor_depth' ) :
    depth_type = get_type ( data_var . sensor_depth )
    depths = np . asarray ( [ data_var . sensor_depth ] * len ( times ) ) . flatten ( )
    values = data_var [ : ] . flatten ( )
elif depth_var is None :
    depths = np . asarray ( [ np . nan ] * len ( times ) ) . flatten ( )
    depth_type = get_type ( depths )
    values = data_var [ : ] . flatten ( )
else :
    depths = depth_var [ : ]
    depth_type = get_type ( depths )
    if len ( data_var . shape ) > 1 :
        times = np . repeat ( times , depths . size )
        depths = np . tile ( depths , original_times_size )
        values = data_var [ : , : ] . flatten ( )
    else :
        values = data_var [ : ] . flatten ( )
    if getattr ( depth_var , 'positive' , 'down' ) . lower ( ) == 'up' :
        logger . warning ( "Converting depths to positive down before returning the DataFrame" )
        depths = depths * - 1
# https : / / github . com / numpy / numpy / issues / 4595
# We can ' t call astype on a MaskedConstant
if ( isinstance ( depths , np . ma . core . MaskedConstant ) or ( hasattr ( depths , 'mask' ) and depths . mask . all ( ) ) ) :
    depths = np . asarray ( [ np . nan ] * len ( times ) ) . flatten ( )
df = pd . DataFrame ( { 'time' : times , 'value' : values . astype ( data_var . dtype ) , 'unit' : data_var . units if hasattr ( data_var , 'units' ) else np . nan , 'depth' : depths . astype ( depth_type ) } )
df . set_index ( [ pd . DatetimeIndex ( df [ 'time' ] ) , pd . Float64Index ( df [ 'depth' ] ) ] , inplace = True )
return df


signature:
async def github_request ( session , api_token , query = None , mutation = None , variables = None ) :
    """Send a request to the GitHub v4 ( GraphQL ) API .
 The request is asynchronous , with asyncio .
 Parameters
 session : ` aiohttp . ClientSession `
 Your application ' s aiohttp client session .
 api _ token : ` str `
 A GitHub personal API token . See the ` GitHub personal access token
 guide ` _ .
 query : ` str ` or ` GitHubQuery `
 GraphQL query string . If provided , then the ` ` mutation ` ` parameter
 should not be set . For examples , see the ` GitHub guide to query and
 mutation operations ` _ .
 mutation : ` str ` or ` GitHubQuery `
 GraphQL mutation string . If provided , then the ` ` query ` ` parameter
 should not be set . For examples , see the ` GitHub guide to query and
 mutation operations ` _ .
 variables : ` dict `
 GraphQL variables , as a JSON - compatible dictionary . This is only
 required if the ` ` query ` ` or ` ` mutation ` ` uses GraphQL variables .
 Returns
 data : ` dict `
 Parsed JSON as a ` dict ` object .
 . . ` GitHub personal access token guide ` : https : / / ls . st / 41d
 . . ` GitHub guide to query and mutation operations ` : https : / / ls . st / 9s7"""

implementation:
payload = { }
if query is not None :
    payload [ 'query' ] = str ( query )
    # converts a GitHubQuery
if mutation is not None :
    payload [ 'mutation' ] = str ( mutation )
    # converts a GitHubQuery
if variables is not None :
    payload [ 'variables' ] = variables
headers = { 'Authorization' : 'token {}' . format ( api_token ) }
url = 'https://api.github.com/graphql'
async with session . post ( url , json = payload , headers = headers ) as response :
    data = await response . json ( )
return data


signature:
def load ( cls , query_name ) :
    """Load a pre - made query .
 These queries are distributed with lsstprojectmeta . See
 : file : ` lsstrojectmeta / data / githubv4 / README . rst ` inside the
 package repository for details on available queries .
 Parameters
 query _ name : ` str `
 Name of the query , such as ` ` ' technote _ repo ' ` ` .
 Returns
 github _ query : ` GitHubQuery
 A GitHub query or mutation object that you can pass to
 ` github _ request ` to execute the request itself ."""

implementation:
template_path = os . path . join ( os . path . dirname ( __file__ ) , '../data/githubv4' , query_name + '.graphql' )
with open ( template_path ) as f :
    query_data = f . read ( )
return cls ( query_data , name = query_name )


signature:
def read_git_commit_timestamp_for_file ( filepath , repo_path = None , repo = None ) :
    """Obtain the timestamp for the most recent commit to a given file in a
 Git repository .
 Parameters
 filepath : ` str `
 Absolute or repository - relative path for a file .
 repo _ path : ` str ` , optional
 Path to the Git repository . Leave as ` None ` to use the current working
 directory or if a ` ` repo ` ` argument is provided .
 repo : ` git . Repo ` , optional
 A ` git . Repo ` instance .
 Returns
 commit _ timestamp : ` datetime . datetime `
 The datetime of the most recent commit to the given file .
 Raises
 IOError
 Raised if the ` ` filepath ` ` does not exist in the Git repository ."""

implementation:
logger = logging . getLogger ( __name__ )
if repo is None :
    repo = git . repo . base . Repo ( path = repo_path , search_parent_directories = True )
repo_path = repo . working_tree_dir
head_commit = repo . head . commit
# filepath relative to the repo path
logger . debug ( 'Using Git repo at %r' , repo_path )
filepath = os . path . relpath ( os . path . abspath ( filepath ) , start = repo_path )
logger . debug ( 'Repo-relative filepath is %r' , filepath )
# Most recent commit datetime of the given file .
# Don ' t use head _ commit . iter _ parents because then it skips the
# commit of a file that ' s added but never modified .
for commit in head_commit . iter_items ( repo , head_commit , [ filepath ] , skip = 0 ) :
    return commit . committed_datetime
# Only get here if git could not find the file path in the history
raise IOError ( 'File {} not found' . format ( filepath ) )