I have a huge list with huge sublists of the form
list={{a,b,c,d},{e,f,g,h},{i,j,k,l}}
I am looking for a way to manipulate these sublists based on the positions of the elements. Something like
list/.{j_,k_,l_,m_}->{j-1,k,l,m}
but without having to write the whole pattern. Is there any way to specify such manipulation based on the position of the element? Something like
list/.#[[1]] & -> #[[1]] - 1 &
that would work?
Answer
You could use: MapAt
:
MapAt[ # - 1 &, list, {All, 1}]
{{-1 + a, b, c, d}, {-1 + e, f, g, h}, {-1 + i, j, k, l}}
or Apply
at the first level (shorthand @@@
) (see also SlotSequence
, shorthand ##n
):
{#1 - 1, ##2}& @@@ list
Comments
Post a Comment