#NEWLINE# def filterWithIndex( vec , f , lowIndex = 0 , highIndex = None , depth = 0 ) : #NEWLINE# #INDENT# if ( highIndex is None ) : #NEWLINE# #INDENT# highIndex = len ( vec ) #NEWLINE# #UNINDENT# if ( highIndex < 0 ) : #NEWLINE# #INDENT# highIndex = ( highIndex + len ( vec ) ) #NEWLINE# #UNINDENT# if ( lowIndex < 0 ) : #NEWLINE# #INDENT# lowIndex = ( lowIndex + len ( vec ) ) #NEWLINE# #UNINDENT# if ( lowIndex == highIndex ) : #NEWLINE# #INDENT# return [ ] #NEWLINE# #UNINDENT# if ( ( ( lowIndex + 1 ) == highIndex ) or ( depth > 10 ) ) : #NEWLINE# #INDENT# tr = [ ] #NEWLINE# while ( lowIndex < highIndex ) : #NEWLINE# #INDENT# if f ( vec , lowIndex ) : #NEWLINE# #INDENT# tr = ( tr + [ vec [ lowIndex ] ] ) #NEWLINE# #UNINDENT# lowIndex = ( lowIndex + 1 ) #NEWLINE# #UNINDENT# return tr #NEWLINE# #UNINDENT# mid = ( ( lowIndex + highIndex ) / 2 ) #NEWLINE# return ( filterWithIndex ( vec , f , lowIndex , mid , ( depth + 1 ) ) + filterWithIndex ( vec , f , mid , highIndex , ( depth + 1 ) ) )