Improve same_value efficiency
This commit is contained in:
parent
fb0e548243
commit
df29d0378b
1 changed files with 2 additions and 4 deletions
6
utils.py
6
utils.py
|
@ -210,10 +210,8 @@ def same_value( list_ ):
|
||||||
raise ValueError( 'list_ must be a list, ' + type( list_ ) + ' given' )
|
raise ValueError( 'list_ must be a list, ' + type( list_ ) + ' given' )
|
||||||
if len( list_ ) == 0:
|
if len( list_ ) == 0:
|
||||||
return list_
|
return list_
|
||||||
index = last_same_value( list_ )
|
counter = np.arange( 1 , len( list_ ) )
|
||||||
if index == len( list_ ) - 1:
|
return np.split( list_ , counter[ list_[ 1 : ] != list_[ : - 1 ] ] )
|
||||||
return [ list_ ]
|
|
||||||
return same_value( list_[ : index + 1 ] ) + same_value( list_[ index + 1 : ] )
|
|
||||||
def last_same_value( list_ ):
|
def last_same_value( list_ ):
|
||||||
"""
|
"""
|
||||||
return the last index of the first same value list
|
return the last index of the first same value list
|
||||||
|
|
Loading…
Reference in a new issue