code: def truncate(string, maxlen, end=True):
      
      if maxlen <= 3:
          raise ValueError('maxlen <= 3')
  
      if len(string) <= maxlen:
          return string
  
      if end:
          return string[:maxlen - 3] + '...'
  
      return '...' + string[3 - maxlen:]
docs: Truncate a string.
  
      Parameters
      ----------
      string : `str`
          String to truncate.
      maxlen : `int`
          Maximum string length.
      end : `boolean`, optional
          Remove characters from the end (default: `True`).
  
      Raises
      ------
      ValueError
          If `maxlen` <= 3.
  
      Returns
      -------
      `str`
          Truncated string.
  
      Examples
      --------
      >>> truncate('str', 6)
      'str'
      >>> truncate('long string', 8)
      'long ...'
      >>> truncate('long string', 8, False)
      '...tring'