def trunc_string(text, max_length, suffix='...'):
 if (len(text) <= max_length):
  return text
 else:
  hard_truncated = text[:(max_length - len(suffix))]
  word_truncated = hard_truncated.rsplit(' ', 1)[0]
  return (word_truncated + suffix)

def trunc_string ( text , max_length , suffix = '...' ) : if ( len ( text ) <= max_length ) : return text else : hard_truncated = text [ : ( max_length - len ( suffix ) ) ] word_truncated = hard_truncated . rsplit ( ' ' , 1 ) [ 0 ] return ( word_truncated + suffix )
truncate a string .