Generate certain list from two lists
Yes you can use MapThread
:
l3 = Join @@ MapThread[Function[{x, y}, Insert[x, #, 3] & /@ y], {l1, l2}]
Here's a more esoteric version that builds lists of mapping operators from l2
and then applies them to the elements of l1
:
l3 = Join @@ MapThread[Through[#1[#2]] &, {Map[Insert[#, 3] &, l2, {2}], l1}]
See here for a discussion of the Through[#1[#2]]&
operator.
You can also MapThread
the function Thread[Insert[#, #2, 3]] &
on the pair of lists {l1,l2}
:
Join @@ MapThread[Thread[Insert[#, #2, 3]] &, {l1, l2}]
{{Mn, Mn1, {1, 1, 0.}, 1., B, 1.4}, {Mn, Mn1, {11, 11, 0.}, 1., B, 1.4},
{Al, Al1, {2, 2, 0.}, 1., B, 1.4}, {Al, Al1, {22, 22, 0.}, 1., B, 1.4}, {Al, Al1, {222, 222, 0.}, 1., B, 1.4}}
Alternatively, use the MapThread/Thread
combination to create pairings appended with 3
and apply Insert
to the resulting triples:
Join @@ Apply[Insert,
MapThread[Thread[{##, 3}, List, {2}] &, {l1, l2}],
{2}]
same result