How do I apply this operation to a list?
Outer[Append, mylist, mysecondlist, 1]
{{{a, b, 1}, {a, b, 2}}, {{c, d, 1}, {c, d, 2}}}
Also
Outer[Join, mylist, List /@ mysecondlist, 1]
Flatten /@ Tuples[{{#}, mysecondlist}] & /@ mylist
Flatten /@ Thread[{#, mysecondlist}, List, {2}] & /@ mylist
Distribute[{mylist, mysecondlist}, List, List, Partition[{##}, 2] &, Append]
all give
{{{a, b, 1}, {a, b, 2}}, {{c, d, 1}, {c, d, 2}}}
My train of thought to tackle that problem would be the following:
Each of the elements of your desired solution has the elements of the second list appended.
I would first try to construct each element separately. The first element would be.
Append[{a, b}, #] & /@ mysecondlist
which gives
{{a, b, 1}, {a, b, 2}}
Afterwards I would replace {a,b}
by a variable and use Map
to obtain a list of all elements.
Function[{x}, Append[x, #] & /@ mysecondlist] /@ mylist
which gives
{{{a, b, 1}, {a, b, 2}}, {{c, d, 1}, {c, d, 2}}}
So in short: Try to divide the problem in smaller, easier solvable chunks.