I want to get a list from a parent list (containing sub-lists of unequal length) using Cases
and a matching pattern. The parent list is
data = {{x,y,z,a},{a,x^m,y^n},{a,b^m}, {a,x,b,c}}
I want to pick the matching patterns (x^_,y^_)
from the sub-lists and keep them in a similar list format.
Using Cases
(at level spec 2), I could almost achieve that but unfortunately, it writes in a single list (instead of keeping the patterns in the same sub-list from where they belong). Eg,
Cases[data,Alternatives@@{x|x^_,y|y^_},2]
gives me
{x, y, x^m, y^n, x}
whereas, the output I want
{{x, y}, {x^m, y^n}, {}, {x}}
such that the final findings corresponding to the matched pattern result similar format (even if it is an empty sub-list).
Map[Cases[#,...yourpattern...]&,data]
That should useCases
on each of your sublists and return the results from each of those as a list and then all those lists will be returned in an enclosing list. $\endgroup$