Here's a following list:
L={{a,b},{c,d},{e,f}}. I want a function such that it sums a number over the first element of each pair. For instance, take the number 1. I need:
L={{a+1,b}, {c+1,d}, {e+1,f}}. Which function does this?
Thanks!
Mathematica Stack Exchange is a question and answer site for users of Wolfram Mathematica. It only takes a minute to sign up.
Sign up to join this communityClear[a, b, c, d, e, f]
lst = {{a, b}, {c, d}, {e, f}}
"TranslationTransform (JM's soln):"
TranslationTransform[{1, 0}]@lst
"ReplaceAll:"
lst /. {{x_, y_} -> {x + 1, y}}
"The ever reliable Map:"
{1 + First@#, Last@#} & /@ lst
"ReplacePart:"
ReplacePart[lst, xy : {_, 1} :> Extract[lst, xy] + 1]
"Part (JimB's answer); changes `lst`!:"
lst[[All, 1]] += 1 (* this is not the answer *)
lst (* this is *)
TranslationTransform[{1, 0}][{{a,b},{c,d},{e,f}}]
$\endgroup$L[[All, 1]] = L[[All, 1]] + 1
. $\endgroup$