How to join and 'multiply' two lists?
RememberOuter
everytime you try to do something you call as 'multiply'.
Outer[Join, A, B, 1]
{{{1, 2, 3, 1, 2}, {1, 2, 3, 3, 4}, {1, 2, 3, 4, 5}}, {{1, 0, 3, 1, 2}, {1, 0, 3, 3, 4}, {1, 0, 3, 4, 5}}}
Join
as the function, and A
and B
as two vectors, then do Outer
at level 1 shall give you a proper result.
I don't know what you want for the second part of your question, but I suppose adding a filter directly to A
will do the job:
Select[A,#[[2]]!=2&]
This appears to be 7-10 times faster than Outer
, depending of lists length:
With[{l = Length[B]},
Function[
subA, Join[ConstantArray[subA, l], B, 2]
] /@ A
]
Join @@@ Tuples[{A, B}]
{{1, 2, 3, 1, 2}, {1, 2, 3, 3, 4}, {1, 2, 3, 4, 5}, {1, 0, 3, 1, 2}, {1, 0, 3, 3, 4}, {1, 0, 3, 4, 5}}
or
Distribute[{A, B}, List, List, List, Join]
{{1, 2, 3, 1, 2}, {1, 2, 3, 3, 4}, {1, 2, 3, 4, 5}, {1, 0, 3, 1, 2}, {1, 0, 3, 3, 4}, {1, 0, 3, 4, 5}}