Improve same_value efficiency

This commit is contained in:
linarphy 2023-06-19 13:31:50 +02:00
parent fb0e548243
commit df29d0378b
No known key found for this signature in database
GPG key ID: 3D4AAAC3AD16E79C

View file

@ -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