code: def is_valid_hostname(hostname):
      '''Return True if hostname is valid, otherwise False.'''
      if not isinstance(hostname, str):
          raise TypeError('hostname must be a string')
      # strip exactly one dot from the right, if present
      if hostname and hostname[-1] == ".":
          hostname = hostname[:-1]
      if not hostname or len(hostname) > 253:
          return False
      labels = hostname.split('.')
      # the TLD must be not all-numeric
      if re.match(NUMERIC_REGEX, labels[-1]):
          return False
      return all(LABEL_REGEX.match(label) for label in labelsf is_valid_hostname(hostname):
      '''Return True if hostname is valid, otherwise False.'''
      if not isinstance(hostname, str):
          raise TypeError('hostname must be a string')
      # strip exactly one dot from the right, if present
      if hostname and hostname[-1] == ".":
          hostname = hostname[:-1]
      if not hostname or len(hostname) > 253:
          return False
      labels = hostname.split('.')
      # the TLD must be not all-numeric
      if re.match(NUMERIC_REGEX, labels[-1]):
          return False
      return all(LABEL_REGEX.match(label) for label in labels)
docs: Return True if hostname is valid, otherwise False.