This can be done reasonably quickly with Position
. First, we get the positions of p
or d
within list1
:
pos1 = Position[list1, _p | _d]
(* {{1, 1}, {1, 2}, {2, 1}, {3, 1}, {3, 2}, {3, 3}, {3, 4}} *)
then we do the equivalent thing for list2
:
pos2 = Position[list2, {_?NumericQ, _, _}]
(* {{1, 1}, {1, 2}, {2, 1}, {3, 1}, {3, 2}, {3, 3}, {3, 4}} *)
A quick visual inspection reveals that the lists are the same, but they can easily be tested programmatically, too.
If you want a partial match, i.e. you wish to match p
only, then pos1
is only going to contain a subset of pos2
, e.g.
pos3 = Position[list1, _p]
(* {{1, 1}, {1, 2}, {2, 1}, {3, 1}, {3, 2}, {3, 3}} *)
Then, to determine whether there is a triplet at these positions in list2
, we use Complement
Complement[pos3, pos2]
(* {} *)
which returns all elements present in pos3
not in pos2
.
Dimensions[list1]; Dimensions[list2]
says the dimensions is the same. $\endgroup$list1
ap[z]
into the second sublist Dimensions still says they are equal. $\endgroup$listN/. x_ /; Head[x] =!= List :> 0
$\endgroup$Dimensions[list2[[1]]]
and so on. Mathematica sees each list as having 3 lists in it. But each list itself can also have other lists inside it. and so on. $\endgroup$