code: def parse_accept_header(accept):
      
      result = []
      for media_range in accept.split(","):
          parts = media_range.split(";")
          media_type = parts.pop(0).strip()
          media_params = []
          q = 1.0
          for part in parts:
              (key, value) = part.lstrip().split("=", 1)
              if key == "q":
                  q = float(value)
              else:
                  media_params.append((key, value))
          result.append((media_type, tuple(media_params), q))
      result.sort(key=lambda x: -x[2])
      return result
docs: Parse an HTTP Accept header.
  
      Parses *accept*, returning a list with pairs of
      (media_type, q_value), ordered by q values.
  
      Adapted from <https://djangosnippets.org/snippets/1042/>