# How can one nested list be used to find the positions of those values in another nested list?

lista = {{0., 1., 0.1, 0.}, {0., 1., 0.2, 0.}, {0., 1., 0.3, 0.}};

listb = {
{0., 1., 1., 0.}, {0., 0.85, 1., 0.}, {0., 1., 0.1, 0.},
{0.,1., 0.2, 0.}, {0., 1., 0.3, 0.}, {0., 1., 0.4, 0.},
{0., 1., 0.55, 0.}, {0., 1., 0.7, 0.}, {0., 1., 0.85, 0.},
{0.4, 0.4, 0.2, 0.1}, {0.4, 0.4, 0.4, 0.1}, {0.4, 0.4, 0.7, 0.1},
{0.4, 0.7, 0., 0.1}, {0.4, 0.7, 0.1, 0.1}, {0.4, 0.7, 0.2, 0.1},
{0.4, 0.7, 0.4, 0.1}, {0.4, 0.7, 0.7, 0.1}, {0.5, 0.4, 0.4, 0.},
{1., 0., 0., 0.1}, {0., 1., 0., 0.1}, {0., 0., 1., 0.1},
{0.,1., 1., 0.1}, {1., 0., 1., 0.1}, {1., 1., 0., 0.1}};


How would one go about finding the first positions of lista sublists in listb?

-
@R.M I would presume that's exactly what the OP wants. – rcollyer Apr 4 '12 at 1:19
I've reduced the lists to make this easier to see, and yes I just need the positions of each sublist from lista in listb. – R Hall Apr 4 '12 at 1:23

How about mapping Position like so

Position[listb, #] & /@ lista
(*{{{3}}, {{4}}, {{5}}, {{6}}, {{7}}, {{8}}, {{9}}, {{1}}, {{2}}}*)


which gives the position of each sublist of lista in listb?

To get only the first instance, use

Position[listb, #, 1, 1] & /@ lista


(the last argument of Position specifies how many positions found to return; the penultimate argument specifies the level at which to search).

-
And with a Flatten you get the simple positions. – FJRA Apr 4 '12 at 1:22
This looks very good, but how can I get the first incidence of lista in listb? IT looks like there are some duplicate sublists in listb. Thanks! – R Hall Apr 4 '12 at 1:25
@RHall does my edit not select only the first instance? – acl Apr 4 '12 at 1:53
Why yes it does! Thanks very much @acl! – R Hall Apr 4 '12 at 1:57
Position[listb, Alternatives@@ lista]

-
very nice. isn't Position[listb, Alternatives @@ lista] cleaner? – acl Apr 4 '12 at 1:33
@acl Tnx. For some reason it didn't work the first time I tried. Probably I typed something wrong. – Dr. belisarius Apr 4 '12 at 1:35
@belisarius both solutions select multiple incidences of sublists from lista out of listb data. (I made the data set very small for easy reading) but on larger lists duplicate sublists are selected. Thanks for your help! – R Hall Apr 4 '12 at 1:45
@RHall Sorry, I missed the word "first" in your q. – Dr. belisarius Apr 4 '12 at 2:16
no @elisarius it is my fault as I edited my post probably right after your first reading. I must be more careful with that in the future. Thanks again for your help! – R Hall Apr 4 '12 at 9:29