Quantcast
Viewing all articles
Browse latest Browse all 186

Map, applying list in a defined function

Suppose I have defined some function (This is arbitrary)

 F[alpha_,a_,b_,c_]:=List[alpha,a+b+c]

I want to apply this F for a given huge list of sets

 {{alpha1, {a1,b1,c1}}, {alpha2, {a2,b2,c2}}, {alpha3, {a3,b3,c3}}}

Of course, I can plug this individually, but is there any smart way of plugging these lists into the function $F$ defined above?

For example, I know,

   F /@ List[a, b, c]

produce

 {F[a], F[b], F[c]}

So my first trial was just

  F /@ {{alpha1, {a1, b1, c1}}, {alpha2, {a2, b2, c2}}, alpha3, {a3, b3, c3}}}

But this gives an extra list outside and inside for $\{a1,b1,c1\}$. i.e.,

 {F[{alpha1, {a1, b1, c1}}], F[{alpha2, {a2, b2, c2}}], F[{alpha3, {a3, b3, c3}}]}

How one can do it wisely?


My solution is given as follows :

 Map[F[#[[1]], Sequence@@#[[2]]] &, {alpha1, {a1, b1, c1}}, {alpha2, {a2, b2, c2}}, {alpha3, {a3, b3, c3}}}]

then it produces desired one


Viewing all articles
Browse latest Browse all 186

Trending Articles