def split_on_groups(string, groups):
 if (not groups):
  return [string]
 boundaries = sorted(set(functools.reduce((lambda l, x: (l + list(x))), groups, [])))
 if (boundaries[0] != 0):
  boundaries.insert(0, 0)
 if (boundaries[(-1)] != len(string)):
  boundaries.append(len(string))
 groups = [string[start:end] for (start, end) in zip(boundaries[:(-1)], boundaries[1:])]
 return [g for g in groups if g]

def split_on_groups ( string , groups ) : if ( not groups ) : return [ string ] boundaries = sorted ( set ( functools . reduce ( ( lambda l , x : ( l + list ( x ) ) ) , groups , [ ] ) ) ) if ( boundaries [ 0 ] != 0 ) : boundaries . insert ( 0 , 0 ) if ( boundaries [ ( - 1 ) ] != len ( string ) ) : boundaries . append ( len ( string ) ) groups = [ string [ start : end ] for ( start , end ) in zip ( boundaries [ : ( - 1 ) ] , boundaries [ 1 : ] ) ] return [ g for g in groups if g ]
split the given string using the different known groups for boundaries .