I have $L$ a 2d list, and $P$ a list of lists of $L$ 1d-index.
Lists in $P$ should be seen as "$L$-picking charts".
Let $(p_{i,1},p_{i,2},\dots,p_{i,n})$ be the $i$-th element of $P$, it's meaning will be:
- pick a first object from the $p_{i,1}$-th list in $L$
- pick a second object from the $p_{i,2}$-th list in $L$
- ...
- pick a last object from the $p_{i,n}$-th list in $L$
So for each element in $P$ I want to create all possible tuples of $L$ 2d-index accordingly to the criteria above.
($L$ objects are completely irrelevant, what matters is just their length... But of course, without a bit of context it would have seemed a weird problem)
L = {{1,2,3,4,5}, {13,17,19}, {81,-144,0,-6}, {0,1}, {1729}, {4,6,10,16,26}};
picker[P_] :=
Module[{ranges, picked = {}},
ranges = MapAt[Length@L[[#]]&, P, {All, All}];
Do[
picked = Join[picked, Transpose[{P[[i]], #}]&/@Tuples[ Range/@ranges[[i]] ]]
, {i, Length@P}];
picked
]
picker[{{3,4},{2,4,4,5}}]
{{{3, 1}, {4, 1}}, {{3, 1}, {4, 2}}, {{3, 2}, {4, 1}}, {{3, 2}, {4, 2}}, {{3, 3}, {4, 1}}, {{3, 3}, {4, 2}}, {{3, 4}, {4, 1}}, {{3, 4}, {4, 2}}, {{2, 1}, {4, 1}, {4, 1}, {5, 1}}, {{2, 1}, {4, 1}, {4, 2}, {5, 1}}, {{2, 1}, {4, 2}, {4, 1}, {5, 1}}, {{2, 1}, {4, 2}, {4, 2}, {5, 1}}, {{2, 2}, {4, 1}, {4, 1}, {5, 1}}, {{2, 2}, {4, 1}, {4, 2}, {5, 1}}, {{2, 2}, {4, 2}, {4, 1}, {5, 1}}, {{2, 2}, {4, 2}, {4, 2}, {5, 1}}, {{2, 3}, {4, 1}, {4, 1}, {5, 1}}, {{2, 3}, {4, 1}, {4, 2}, {5, 1}}, {{2, 3}, {4, 2}, {4, 1}, {5, 1}}, {{2, 3}, {4, 2}, {4, 2}, {5, 1}}}
The code works, but it seems a bit too sophisticated, is there a more elegant solution?
N.B.: The function should return all the tuples in one common list and not in Length@P
separated lists