For example
mat={{a,b},{c,a,a}}
How to write a function posindex
that posindex[mat]
will give
{{a -> {1, 1}, b -> {1, 2}}, {c -> {2, 1}, a -> {2, 2}, a -> {2, 3}}
And the function should also work for more complex list, for example
{{a,b},{c,{a},a}}
What is more, it should also work for elements that are expr, eg
{{a,b},{c,{10a},a}}
Summary
I accept Michael E2's answer, because it is by far the only one works for all the above cases and the thought behind the function elempos
is easy to understand.
kglr's solution has the advantage of using built-in function MapIndexed
. It works fine for list that contains only atomic expr. But fails when there is both complex level and non-atomic expr. But it is a quite useful solution in many case, what is more it provides level control that elempos
doesn't have.