This question relates to the recent question in: Creating permutations on a sublist of the list {1, 2, ..., n}
The following was suggested to create rules, then permutations using these rules:
list = Range[7] permutations = Thread[{1, 3, 7} -> #] & /@ Permutations[{1, 3, 7}] list /. permutations This results in:
{{1, 2, 3, 4, 5, 6, 7}, {1, 2, 7, 4, 5, 6, 3}, {3, 2, 1, 4, 5, 6, 7}, {3, 2, 7, 4, 5, 6, 1}, {7, 2, 1, 4, 5, 6, 3}, {7, 2, 3, 4, 5, 6, 1}} In other words, the list {1,2,3,4,5,6,7} is permuted in the positions 1, 3 and 7 in all possible ways.
I'd like to execute this operation repeatedly on the list {1,2,3,4,5,6,7} and collect all outcomes in a single list. For instance:
Given the list of lists {{1,3,7}, {3,4,6,7}} (which can have more than 2 elements) I need the output:
{{1, 2, 3, 4, 5, 6, 7}, {1, 2, 7, 4, 5, 6, 3}, {3, 2, 1, 4, 5, 6, 7}, {3, 2, 7, 4, 5, 6, 1}, {7, 2, 1, 4, 5, 6, 3}, {7, 2, 3, 4, 5, 6, 1}, {1, 2, 3, 4, 5, 6, 7}, {1, 2, 3, 4, 5, 7, 6}, {1, 2, 3, 6, 5, 4, 7}, {1, 2, 3, 6, 5, 7, 4}, {1, 2, 3, 7, 5, 4, 6}, {1, 2, 3, 7, 5, 6, 4}, {1, 2, 4, 3, 5, 6, 7}, {1, 2, 4, 3, 5, 7, 6}, {1, 2, 4, 6, 5, 3, 7}, {1, 2, 4, 6, 5, 7, 3}, {1, 2, 4, 7, 5, 3, 6}, {1, 2, 4, 7, 5, 6, 3}, {1, 2, 6, 3, 5, 4, 7}, {1, 2, 6, 3, 5, 7, 4}, {1, 2, 6, 4, 5, 3, 7}, {1, 2, 6, 4, 5, 7, 3}, {1, 2, 6, 7, 5, 3, 4}, {1, 2, 6, 7, 5, 4, 3}, {1, 2, 7, 3, 5, 4, 6}, {1, 2, 7, 3, 5, 6, 4}, {1, 2, 7, 4, 5, 3, 6}, {1, 2, 7, 4, 5, 6, 3}, {1, 2, 7, 6, 5, 3, 4}, {1, 2, 7, 6, 5, 4, 3}} In this output, the first six sublists are the original output for {1,3,7}, now combined with the 24 outputs for {3,4,6,7}.
I tried to give the pure function two arguments:
list = Range[7] templist = {{1,3,7}, {3,4,6,7}} permutations = (Thread[#1 -> #2] & /@ Permutations[#1])& /@ templist list /. permutations This fails. I cannot get the arguments to be passed correctly to #1 and #2. Can you clarify how multiple arguments can be used properly for the case of pure functions in this example?