2
$\begingroup$

I have a list of this type p = {{y, 1, 3}, {x, 2, 0}, {z, 3, 1/(k + 1)}}

I can use a Do loop that is

    `In: T = {}; Do[AppendTo[T, p[[i]][[1]] -> p[[i]][[2]]  p[[i]][[1]] + p[[i]][[3]]], {i, Length[p]}]
    In: T 
    Out: {y -> 3 + y, x -> 2 x, z -> 1/(1 + k) + 3 z}`

Is there I way I can archive the same output without the Do loop?

$\endgroup$
7
$\begingroup$

The one-liner is

(#1 -> #2 #1 + #3 &) @@@ p

I recommend studying
Where can I find examples of good Mathematica programming practice?
What are the most common pitfalls awaiting new users?
And particularly these answers to the second question:
https://mathematica.stackexchange.com/a/25616/26956
https://mathematica.stackexchange.com/a/18396/26956

$\endgroup$
2
  • $\begingroup$ Output corrected. $\endgroup$ – saintdoe Jul 16 '15 at 19:49
  • $\begingroup$ @evansdoe likewise, the response. $\endgroup$ – LLlAMnYP Jul 16 '15 at 19:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.