I have the following list:
list = {{1, 2}, {2}, {3, 4, 1}, {5, 4}, {3, 3}, {a, b, c}, {e, f}, {g}, {}, {Sin[a], Cos[b]}};
I should use Cases
function Cases[list, pattern -> expr]
with patterns or rules to get the following sums:
(a) the sum of all subexpressions with the length 2. Result:
{3,9,6,e+f,Cos[b]+Sin[a]}
(b) as in (a), but only for Integer numbers. Result:
{3,9,6}
(c) the sum of all subexpressions with the length >= 2. Result:
{3,8,9,6,a+b+c,e+f,Cos[b]+Sin[a]}
(d) the sum of ALL subexpressions. Result:
{3,2,8,9,6,a+b+c,e+f,g,0,Cos[b]+Sin[a]}
PS. It's not a homework. I learn for a test. This is an exercise I don't understand. Thanks for your help!
Cases[list, _?(Length[#] == 2 &)]
picks out the right elements,Total/@Cases[list, _?(Length[#] == 2 &)]
gets their sums. $\endgroup$