code: def list_by_x(prs, key):
      
      if key == "type":
          kfn = operator.methodcaller(key)
          res = sorted(((k, sort_by_prio(g)) for k, g
                        in anyconfig.utils.groupby(prs, kfn)),
                       key=operator.itemgetter(0))
  
      elif key == "extensions":
          res = select_by_key(((p.extensions(), p) for p in prs),
                              sort_fn=sort_by_prio)
      else:
          raise ValueError("Argument 'key' must be 'type' or "
                           "'extensions' but it was '%s'" % key)
  
      return res
docs: :param key: Grouping key, "type" or "extensions"
      :return:
          A list of :class:`Processor` or its children classes grouped by
          given 'item', [(cid, [:class:`Processor`)]] by default