How to drop/extract elements of a list which starts with Plus
list = {a^2, b^2, a^-1, a^2+b^2, (a+b+c)^-1, (a+b-c)^-2};
{list1, list2} = GatherBy[list, Head]
(* Out:
{
{a^2, b^2, a^(-1), (a + b + c)^(-1), (a + b - c)^(-2)},
{a^2 + b^2}
}
*)
If you want to specify in which order the heads should be extracted, then you could use multiple Cases statements:
{powerList, plusList} = Cases[list, Blank[#]]& /@ {Power, Plus}
(* Out:
{
{a^2, b^2, 1/a, 1/(a + b + c), 1/(a + b - c)^2},
{a^2 + b^2}}
}
*)
{l1, l2} = Function[x, Select[#, #[[0]] === x &]]&[list]/@{Power, Plus}
Alternatively, using Pick
:
{lone,ltwo} = Pick[#1, #1[[All,0]], #2]&[list,#]&/@{Power, Plus}
l1
l2
$$ \left\{a^2,b^2,\frac{1}{a},\frac{1}{a+b+c},\frac{1}{(a+b-c)^2}\right\} $$
$$ \left\{a^2+b^2\right\} $$
Cases do the job.
{a^2, b^2, a^-1, a^2 + b^2, (a + b + c)^-1, (a + b - c)^-2} // {Cases[_Power]@#, Cases[_Plus]@#} &