Is it possible to use # in the select function preserving the structure of the list?
Here an example of what I mean. Let's say I want to select all the pairs where the first element is 1:
data1 = {{1, 2}, {1, 3}, {3, 4}, {4, 4}, {5, 2}};
data2 = {{1, 1}, {1,5}, {3, 5}};
all = {data1, data2};
The output of the function would be:
{{{1,2},{1,3}},{{1,1},{1,5}}}
I tried with Select but I'm not able to preserve the list structure. Here some (failed) attempt:
Select[all, #[[1, 1]] == 1 &]
with the output:
{{{1, 2}, {1, 3}, {3, 4}, {4, 4}, {5, 2}}, {{1, 1}, {1, 5}, {3, 5}}}
because, as far as I understand, # refers to the elements of the outer list (which are data1 and data2).
Or
Select[Flatten[all, 1], #[[1]] == 1 &]
with the output
{{1, 2}, {1, 3}, {1, 1}, {1, 5}}
but the list structure is not preserved.
Any tips? I just started using functional programming and I often get stuck on this simple (I assume) stuff.