code: def best_charset(text):
      
      if isinstance(text, bytes):
          text = text.decode('ascii')
      for charset in 'us-ascii', 'iso-8859-1', 'utf-8':
          try:
              encoded = text.encode(charset)
          except UnicodeError:
              pass
          else:
              return charset, encoded
docs: Find the most human-readable and/or conventional encoding for unicode text.
  
      Prefers `us-ascii` or `iso-8859-1` and falls back to `utf-8`.