# Special merge of two lists

Posted 8 years ago
4416 Views
|
6 Replies
|
2 Total Likes
|
 Hello I have these two lists:  l1={a, b, c} l2={k, l, m} How can I get  {a, b, c, k, a, b, c, l, a, b, c, m}? I toyed with Riffle along the line below to no availThanks Riffle[Sequence@l1, l2] 
6 Replies
Sort By:
Posted 8 years ago
 Slight variation, Join could be faster if it matters: Flatten[l1~Join~{#} & /@ l2] {a, b, c, k, a, b, c, l, a, b, c, m}
Posted 8 years ago
 Thanks - your answer suits me. What is the advantage of the infix form compared to the normal form ie ?  Flatten[Join[l1, {#}]] & /@ l2 
Posted 8 years ago
 Hi Wojtek,this is not very elegant, but it works: l1 = {a, b, c}; l2 = {k, l, m}; Clear[lll]; Flatten[Thread[{lll, l2}] /. lll -> l1] Regards -- Henrik
Posted 8 years ago
 In[12]:= Append[l1, #] & /@ l2 // Flatten Out[12]= {a, b, c, k, a, b, c, l, a, b, c, m} This maps the pure function which appends an element to l1, onto the elements of l2, and then flattens the resulting list.
Posted 8 years ago
 Special merge of two lists
Posted 8 years ago
 Thanks I undestood what is going on only by removing the Flatten