parameters: (string, max_length)
return_statement: return '{0}...{1}'.format(string[:n_1], string[-n_2:])
docstring: https://www.xormedia.com/string-truncate-middle-with-ellipsis/
docstring_summary: https://www.xormedia.com/string-truncate-middle-with-ellipsis/
docstring_tokens: https : // www . xormedia . com / string - truncate - middle - with - ellipsis /
function: def truncate(string, max_length):
      """https://www.xormedia.com/string-truncate-middle-with-ellipsis/"""
      if len(string) <= max_length:
          # string is already short-enough
          return string
      # half of the size, minus the 3 .'s
      n_2 = int(max_length / 2 - 3)
      # whatever's left
      n_1 = max_length - n_2 - 3
      return '{0}...{1}'.format(string[:n_1], string[-n_2:])
function_tokens: def truncate ( string , max_length ) : if len ( string ) <= max_length : # string is already short-enough return string # half of the size, minus the 3 .'s n_2 = int ( max_length / 2 - 3 ) # whatever's left n_1 = max_length - n_2 - 3 return '{0}...{1}' . format ( string [ : n_1 ] , string [ - n_2 : ] )