MapIndexed

MapIndexed[f, expr] returns a new expression with the same head as expr, but with f mapped to each of the arguments. Additionally, MapIdnexed supplies the part specification of the subexpression as the second argument of f. Map[f, expr, levelspec] maps f to all subexpressions that match the level specification levelspec, also supplying the part specification for each subexpression as the second argument to f.

Attributes[MapIndexed] := {Protected}

Simple examples

In[1]:= f[a[f[b[f[c, {1, 1}], f[d, {1, 2}], f[e, {1, 3}]], {1}], f[l[f[g[f[h, {2, 1, 1}], f[j, {2, 1, 2}]], {2, 1}], f[k, {2, 2}]], {2}]], {}]
Out[1]= MapIndexed[f, a[b[c, d, e], l[g[h, j], k]], {Infinity*-1, Infinity}]
In[2]:= a[f[b[f[c, {1, 1}], f[d, {1, 2}], f[e, {1, 3}]], {1}], f[l[f[g[f[h, {2, 1, 1}], f[j, {2, 1, 2}]], {2, 1}], f[k, {2, 2}]], {2}]]
Out[2]= MapIndexed[f, a[b[c, d, e], l[g[h, j], k]], Infinity]
In[3]:= a[f[b[f[c, {1, 1}], f[d, {1, 2}], f[e, {1, 3}]], {1}], l[f[g[f[h, {2, 1, 1}], f[j, {2, 1, 2}]], {2, 1}], f[k, {2, 2}]]]
Out[3]= MapIndexed[f, a[b[c, d, e], l[g[h, j], k]], {-2, Infinity}]
In[4]:= a[b[c, d, e], l[f[g[h, j], {2, 1}], k]]
Out[4]= MapIndexed[f, a[b[c, d, e], l[g[h, j], k]], {2, -2}]
In[5]:= a[f[b[f[c, {1, 1}], f[d, {1, 2}], f[e, {1, 3}]], {1}], f[l[f[g[h, j], {2, 1}], f[k, {2, 2}]], {2}]]
Out[5]= MapIndexed[f, a[b[c, d, e], l[g[h, j], k]], 2]
In[6]:= a[f[b[c, d, e], {1}], f[l[f[g[h, j], {2, 1}], k], {2}]]
Out[6]= MapIndexed[f, a[b[c, d, e], l[g[h, j], k]], -2]