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' )
|
||||
if len( list_ ) == 0:
|
||||
return list_
|
||||
index = last_same_value( list_ )
|
||||
if index == len( list_ ) - 1:
|
||||
return [ list_ ]
|
||||
return same_value( list_[ : index + 1 ] ) + same_value( list_[ index + 1 : ] )
|
||||
counter = np.arange( 1 , len( list_ ) )
|
||||
return np.split( list_ , counter[ list_[ 1 : ] != list_[ : - 1 ] ] )
|
||||
def last_same_value( list_ ):
|
||||
"""
|
||||
return the last index of the first same value list
|
||||
|
|
Loading…
Reference in a new issue