def _words_group(input, strlen):
 words = []
 nblanks = input.count(' ')
 nmax = max(nblanks, ((len(input) // strlen) + 1))
 arr = np.fromstring((input + ' '), dtype=(binary_type, 1))
 blank_loc = np.nonzero((arr == ' '))[0]
 offset = 0
 xoffset = 0
 for idx in range(nmax):
  try:
   loc = np.nonzero((blank_loc >= (strlen + offset)))[0][0]
   offset = (blank_loc[(loc - 1)] + 1)
   if (loc == 0):
    offset = (-1)
  except Exception:
   offset = len(input)
  if (offset <= xoffset):
   offset = (xoffset + strlen)
  words.append(input[xoffset:offset])
  if (len(input) == offset):
   break
  xoffset = offset
 return words

def _words_group ( input , strlen ) : words = [ ] nblanks = input . count ( ' ' ) nmax = max ( nblanks , ( ( len ( input ) // strlen ) + 1 ) ) arr = np . fromstring ( ( input + ' ' ) , dtype = ( binary_type , 1 ) ) blank_loc = np . nonzero ( ( arr == ' ' ) ) [ 0 ] offset = 0 xoffset = 0 for idx in range ( nmax ) : try : loc = np . nonzero ( ( blank_loc >= ( strlen + offset ) ) ) [ 0 ] [ 0 ] offset = ( blank_loc [ ( loc - 1 ) ] + 1 ) if ( loc == 0 ) : offset = ( - 1 ) except Exception : offset = len ( input ) if ( offset <= xoffset ) : offset = ( xoffset + strlen ) words . append ( input [ xoffset : offset ] ) if ( len ( input ) == offset ) : break xoffset = offset return words
split a long string into parts where each part is no longer than strlen and no word is cut into two pieces .