Generate certain list from two listsDistributing elements across a list of listsHow to find the distance of two lists?One to Many Lists MergePattern matching - comparing two listsContract two listsMatching the order of a master list of lists from a random list of listsEfficiently exchange elements between two listsJoining 100 lists to make one big listSelecting cases from a list based on two conditionsRagged Transpose

Can the removal of a duty-free sales trolley result in a measurable reduction in emissions?

Cathode rays and the cathode rays tube

How to avoid typing 'git' at the begining of every Git command

bash vs. zsh: What are the practical differences?

Why isn't Bash trap working if output is redirected to stdout?

Is Lambda Calculus purely syntactic?

Canada travel to US using Global Entry

Wizard clothing for warm weather

C++ logging library

How to find a better angle and distance for clicking picture of a distorted artwork to achieve 3D effect?

Does the new finding on "reversing a quantum jump mid-flight" rule out any interpretations of QM?

How far would a landing Airbus A380 go until it stops with no brakes?

Convert only certain words to lowercase

Rail-to-rail op-amp only reaches 90% of VCC, works sometimes, not everytime

Do you need to let the DM know when you are multiclassing?

The significance of kelvin as a unit of absolute temperature

Three questions

Do you have to have figures when playing D&D?

Is there a DSLR/mirorless camera with minimal options like a classic, simple SLR?

Why are ambiguous grammars bad?

Does putting salt first make it easier for attacker to bruteforce the hash?

How to befriend someone who doesn't like to talk?

Are the guests in Westworld forbidden to tell the hosts that they are robots?

Use 1 9 6 2 in this order to make 75



Generate certain list from two lists


Distributing elements across a list of listsHow to find the distance of two lists?One to Many Lists MergePattern matching - comparing two listsContract two listsMatching the order of a master list of lists from a random list of listsEfficiently exchange elements between two listsJoining 100 lists to make one big listSelecting cases from a list based on two conditionsRagged Transpose













3












$begingroup$


I have two lists.



l1=
"Mn", "Mn1", 1., "B", 1.4,
"Al", "Al1", 1., "B", 1.4
;

l2=
1, 1, 0., 11, 11, 0.,

2, 2, 0., 22, 22, 0., 222, 222, 0.



This is a short version of the lists. The two lists always have the same Length so that their level-1 elements have a one-to-one relation. However, the elements of l2 can have varying Length as shown here.



I'd like to generate a new list as follows.



l3=

"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



I think MapThread might be the direction to go, but I cannot think of any function to obtain the result. I'm not stick to MapThread. Any function that can do the job is okay as long as it's a vertorization method since that's what MMA favors.



Thank you.










share|improve this question











$endgroup$











  • $begingroup$
    Can you elaborate your receipt for l3 in detail? I understand nothing. BTW, the notation "l" is not good: compare with "I" and "1".
    $endgroup$
    – user64494
    8 hours ago










  • $begingroup$
    @user64494, it's really difficult for me to think of a good way to describe the format of l3 for English isn't my first language. That's why I use newlines to separate elements of l1 and l2 and change values of l2 to 1,11 and 2, 22, 222 for clarity. Maybe you could help me with that. But I think the answers provided understood my need and returns the desired format of l3. Also, I appreciate the suggestions of l1/2/3 may not be a good variable name. Thanks.
    $endgroup$
    – Yaofeng
    5 hours ago
















3












$begingroup$


I have two lists.



l1=
"Mn", "Mn1", 1., "B", 1.4,
"Al", "Al1", 1., "B", 1.4
;

l2=
1, 1, 0., 11, 11, 0.,

2, 2, 0., 22, 22, 0., 222, 222, 0.



This is a short version of the lists. The two lists always have the same Length so that their level-1 elements have a one-to-one relation. However, the elements of l2 can have varying Length as shown here.



I'd like to generate a new list as follows.



l3=

"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



I think MapThread might be the direction to go, but I cannot think of any function to obtain the result. I'm not stick to MapThread. Any function that can do the job is okay as long as it's a vertorization method since that's what MMA favors.



Thank you.










share|improve this question











$endgroup$











  • $begingroup$
    Can you elaborate your receipt for l3 in detail? I understand nothing. BTW, the notation "l" is not good: compare with "I" and "1".
    $endgroup$
    – user64494
    8 hours ago










  • $begingroup$
    @user64494, it's really difficult for me to think of a good way to describe the format of l3 for English isn't my first language. That's why I use newlines to separate elements of l1 and l2 and change values of l2 to 1,11 and 2, 22, 222 for clarity. Maybe you could help me with that. But I think the answers provided understood my need and returns the desired format of l3. Also, I appreciate the suggestions of l1/2/3 may not be a good variable name. Thanks.
    $endgroup$
    – Yaofeng
    5 hours ago














3












3








3


1



$begingroup$


I have two lists.



l1=
"Mn", "Mn1", 1., "B", 1.4,
"Al", "Al1", 1., "B", 1.4
;

l2=
1, 1, 0., 11, 11, 0.,

2, 2, 0., 22, 22, 0., 222, 222, 0.



This is a short version of the lists. The two lists always have the same Length so that their level-1 elements have a one-to-one relation. However, the elements of l2 can have varying Length as shown here.



I'd like to generate a new list as follows.



l3=

"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



I think MapThread might be the direction to go, but I cannot think of any function to obtain the result. I'm not stick to MapThread. Any function that can do the job is okay as long as it's a vertorization method since that's what MMA favors.



Thank you.










share|improve this question











$endgroup$




I have two lists.



l1=
"Mn", "Mn1", 1., "B", 1.4,
"Al", "Al1", 1., "B", 1.4
;

l2=
1, 1, 0., 11, 11, 0.,

2, 2, 0., 22, 22, 0., 222, 222, 0.



This is a short version of the lists. The two lists always have the same Length so that their level-1 elements have a one-to-one relation. However, the elements of l2 can have varying Length as shown here.



I'd like to generate a new list as follows.



l3=

"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



I think MapThread might be the direction to go, but I cannot think of any function to obtain the result. I'm not stick to MapThread. Any function that can do the job is okay as long as it's a vertorization method since that's what MMA favors.



Thank you.







list-manipulation






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited 8 hours ago









user64494

3,97111323




3,97111323










asked 8 hours ago









YaofengYaofeng

746




746











  • $begingroup$
    Can you elaborate your receipt for l3 in detail? I understand nothing. BTW, the notation "l" is not good: compare with "I" and "1".
    $endgroup$
    – user64494
    8 hours ago










  • $begingroup$
    @user64494, it's really difficult for me to think of a good way to describe the format of l3 for English isn't my first language. That's why I use newlines to separate elements of l1 and l2 and change values of l2 to 1,11 and 2, 22, 222 for clarity. Maybe you could help me with that. But I think the answers provided understood my need and returns the desired format of l3. Also, I appreciate the suggestions of l1/2/3 may not be a good variable name. Thanks.
    $endgroup$
    – Yaofeng
    5 hours ago

















  • $begingroup$
    Can you elaborate your receipt for l3 in detail? I understand nothing. BTW, the notation "l" is not good: compare with "I" and "1".
    $endgroup$
    – user64494
    8 hours ago










  • $begingroup$
    @user64494, it's really difficult for me to think of a good way to describe the format of l3 for English isn't my first language. That's why I use newlines to separate elements of l1 and l2 and change values of l2 to 1,11 and 2, 22, 222 for clarity. Maybe you could help me with that. But I think the answers provided understood my need and returns the desired format of l3. Also, I appreciate the suggestions of l1/2/3 may not be a good variable name. Thanks.
    $endgroup$
    – Yaofeng
    5 hours ago
















$begingroup$
Can you elaborate your receipt for l3 in detail? I understand nothing. BTW, the notation "l" is not good: compare with "I" and "1".
$endgroup$
– user64494
8 hours ago




$begingroup$
Can you elaborate your receipt for l3 in detail? I understand nothing. BTW, the notation "l" is not good: compare with "I" and "1".
$endgroup$
– user64494
8 hours ago












$begingroup$
@user64494, it's really difficult for me to think of a good way to describe the format of l3 for English isn't my first language. That's why I use newlines to separate elements of l1 and l2 and change values of l2 to 1,11 and 2, 22, 222 for clarity. Maybe you could help me with that. But I think the answers provided understood my need and returns the desired format of l3. Also, I appreciate the suggestions of l1/2/3 may not be a good variable name. Thanks.
$endgroup$
– Yaofeng
5 hours ago





$begingroup$
@user64494, it's really difficult for me to think of a good way to describe the format of l3 for English isn't my first language. That's why I use newlines to separate elements of l1 and l2 and change values of l2 to 1,11 and 2, 22, 222 for clarity. Maybe you could help me with that. But I think the answers provided understood my need and returns the desired format of l3. Also, I appreciate the suggestions of l1/2/3 may not be a good variable name. Thanks.
$endgroup$
– Yaofeng
5 hours ago











2 Answers
2






active

oldest

votes


















3












$begingroup$

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]


The function Through[#1[#2]]& looks very general and useful: does it have a canonical name?






share|improve this answer











$endgroup$












  • $begingroup$
    A good code is a commented code. Comments are useful to both readers and authors.
    $endgroup$
    – user64494
    8 hours ago







  • 3




    $begingroup$
    @user64494 I expect some effort from the reader: the analysis and exegesis of other people's code snippets is a great learning tool. Give a man a fish and you feed him for a day; teach a man to fish and you feed him for a lifetime.
    $endgroup$
    – Roman
    7 hours ago










  • $begingroup$
    @Roman, I like the 1st solution you provided because that's what I can remember in brain once I learn it. I was struggling with Part, but yours enlightened me. I'll need to understand better the Through approach. First time I heard of this function. Thanks.
    $endgroup$
    – Yaofeng
    5 hours ago


















3












$begingroup$

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







share|improve this answer











$endgroup$








  • 1




    $begingroup$
    Yes that's what I was looking for! Thanks. Prefix it with Join@@ to match the spec.
    $endgroup$
    – Roman
    6 hours ago










  • $begingroup$
    @kglr, I never think of using Thread function before reading your answer. It's a little bit difficult for me to appreciate the mechanism of Thread. It's written "threads" f over any lists that appear in args in MMA's help page. But elements of l1 and l2 are both lists. I think Insert plays a role here so that the function only threads over element of l2. Am I understanding correctly? Thanks
    $endgroup$
    – Yaofeng
    5 hours ago










  • $begingroup$
    @Yaofeng, you are right for the first one. In the second, the second and third arguments of Thread controls what to thread over and in which positions.
    $endgroup$
    – kglr
    5 hours ago










  • $begingroup$
    @kglr, I compared the AbsoluteTiming for your Thread solution and Roman's Function solution. Yours is faster. Although it's not intuitive for me at the moment, but I guess that's the direction for me to go, in line with MMA's vectorization. Thanks again!
    $endgroup$
    – Yaofeng
    5 hours ago











Your Answer








StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "387"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmathematica.stackexchange.com%2fquestions%2f200024%2fgenerate-certain-list-from-two-lists%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























2 Answers
2






active

oldest

votes








2 Answers
2






active

oldest

votes









active

oldest

votes






active

oldest

votes









3












$begingroup$

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]


The function Through[#1[#2]]& looks very general and useful: does it have a canonical name?






share|improve this answer











$endgroup$












  • $begingroup$
    A good code is a commented code. Comments are useful to both readers and authors.
    $endgroup$
    – user64494
    8 hours ago







  • 3




    $begingroup$
    @user64494 I expect some effort from the reader: the analysis and exegesis of other people's code snippets is a great learning tool. Give a man a fish and you feed him for a day; teach a man to fish and you feed him for a lifetime.
    $endgroup$
    – Roman
    7 hours ago










  • $begingroup$
    @Roman, I like the 1st solution you provided because that's what I can remember in brain once I learn it. I was struggling with Part, but yours enlightened me. I'll need to understand better the Through approach. First time I heard of this function. Thanks.
    $endgroup$
    – Yaofeng
    5 hours ago















3












$begingroup$

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]


The function Through[#1[#2]]& looks very general and useful: does it have a canonical name?






share|improve this answer











$endgroup$












  • $begingroup$
    A good code is a commented code. Comments are useful to both readers and authors.
    $endgroup$
    – user64494
    8 hours ago







  • 3




    $begingroup$
    @user64494 I expect some effort from the reader: the analysis and exegesis of other people's code snippets is a great learning tool. Give a man a fish and you feed him for a day; teach a man to fish and you feed him for a lifetime.
    $endgroup$
    – Roman
    7 hours ago










  • $begingroup$
    @Roman, I like the 1st solution you provided because that's what I can remember in brain once I learn it. I was struggling with Part, but yours enlightened me. I'll need to understand better the Through approach. First time I heard of this function. Thanks.
    $endgroup$
    – Yaofeng
    5 hours ago













3












3








3





$begingroup$

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]


The function Through[#1[#2]]& looks very general and useful: does it have a canonical name?






share|improve this answer











$endgroup$



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]


The function Through[#1[#2]]& looks very general and useful: does it have a canonical name?







share|improve this answer














share|improve this answer



share|improve this answer








edited 6 hours ago

























answered 8 hours ago









RomanRoman

10.5k11741




10.5k11741











  • $begingroup$
    A good code is a commented code. Comments are useful to both readers and authors.
    $endgroup$
    – user64494
    8 hours ago







  • 3




    $begingroup$
    @user64494 I expect some effort from the reader: the analysis and exegesis of other people's code snippets is a great learning tool. Give a man a fish and you feed him for a day; teach a man to fish and you feed him for a lifetime.
    $endgroup$
    – Roman
    7 hours ago










  • $begingroup$
    @Roman, I like the 1st solution you provided because that's what I can remember in brain once I learn it. I was struggling with Part, but yours enlightened me. I'll need to understand better the Through approach. First time I heard of this function. Thanks.
    $endgroup$
    – Yaofeng
    5 hours ago
















  • $begingroup$
    A good code is a commented code. Comments are useful to both readers and authors.
    $endgroup$
    – user64494
    8 hours ago







  • 3




    $begingroup$
    @user64494 I expect some effort from the reader: the analysis and exegesis of other people's code snippets is a great learning tool. Give a man a fish and you feed him for a day; teach a man to fish and you feed him for a lifetime.
    $endgroup$
    – Roman
    7 hours ago










  • $begingroup$
    @Roman, I like the 1st solution you provided because that's what I can remember in brain once I learn it. I was struggling with Part, but yours enlightened me. I'll need to understand better the Through approach. First time I heard of this function. Thanks.
    $endgroup$
    – Yaofeng
    5 hours ago















$begingroup$
A good code is a commented code. Comments are useful to both readers and authors.
$endgroup$
– user64494
8 hours ago





$begingroup$
A good code is a commented code. Comments are useful to both readers and authors.
$endgroup$
– user64494
8 hours ago





3




3




$begingroup$
@user64494 I expect some effort from the reader: the analysis and exegesis of other people's code snippets is a great learning tool. Give a man a fish and you feed him for a day; teach a man to fish and you feed him for a lifetime.
$endgroup$
– Roman
7 hours ago




$begingroup$
@user64494 I expect some effort from the reader: the analysis and exegesis of other people's code snippets is a great learning tool. Give a man a fish and you feed him for a day; teach a man to fish and you feed him for a lifetime.
$endgroup$
– Roman
7 hours ago












$begingroup$
@Roman, I like the 1st solution you provided because that's what I can remember in brain once I learn it. I was struggling with Part, but yours enlightened me. I'll need to understand better the Through approach. First time I heard of this function. Thanks.
$endgroup$
– Yaofeng
5 hours ago




$begingroup$
@Roman, I like the 1st solution you provided because that's what I can remember in brain once I learn it. I was struggling with Part, but yours enlightened me. I'll need to understand better the Through approach. First time I heard of this function. Thanks.
$endgroup$
– Yaofeng
5 hours ago











3












$begingroup$

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







share|improve this answer











$endgroup$








  • 1




    $begingroup$
    Yes that's what I was looking for! Thanks. Prefix it with Join@@ to match the spec.
    $endgroup$
    – Roman
    6 hours ago










  • $begingroup$
    @kglr, I never think of using Thread function before reading your answer. It's a little bit difficult for me to appreciate the mechanism of Thread. It's written "threads" f over any lists that appear in args in MMA's help page. But elements of l1 and l2 are both lists. I think Insert plays a role here so that the function only threads over element of l2. Am I understanding correctly? Thanks
    $endgroup$
    – Yaofeng
    5 hours ago










  • $begingroup$
    @Yaofeng, you are right for the first one. In the second, the second and third arguments of Thread controls what to thread over and in which positions.
    $endgroup$
    – kglr
    5 hours ago










  • $begingroup$
    @kglr, I compared the AbsoluteTiming for your Thread solution and Roman's Function solution. Yours is faster. Although it's not intuitive for me at the moment, but I guess that's the direction for me to go, in line with MMA's vectorization. Thanks again!
    $endgroup$
    – Yaofeng
    5 hours ago















3












$begingroup$

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







share|improve this answer











$endgroup$








  • 1




    $begingroup$
    Yes that's what I was looking for! Thanks. Prefix it with Join@@ to match the spec.
    $endgroup$
    – Roman
    6 hours ago










  • $begingroup$
    @kglr, I never think of using Thread function before reading your answer. It's a little bit difficult for me to appreciate the mechanism of Thread. It's written "threads" f over any lists that appear in args in MMA's help page. But elements of l1 and l2 are both lists. I think Insert plays a role here so that the function only threads over element of l2. Am I understanding correctly? Thanks
    $endgroup$
    – Yaofeng
    5 hours ago










  • $begingroup$
    @Yaofeng, you are right for the first one. In the second, the second and third arguments of Thread controls what to thread over and in which positions.
    $endgroup$
    – kglr
    5 hours ago










  • $begingroup$
    @kglr, I compared the AbsoluteTiming for your Thread solution and Roman's Function solution. Yours is faster. Although it's not intuitive for me at the moment, but I guess that's the direction for me to go, in line with MMA's vectorization. Thanks again!
    $endgroup$
    – Yaofeng
    5 hours ago













3












3








3





$begingroup$

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







share|improve this answer











$endgroup$



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








share|improve this answer














share|improve this answer



share|improve this answer








edited 2 hours ago

























answered 7 hours ago









kglrkglr

197k10222444




197k10222444







  • 1




    $begingroup$
    Yes that's what I was looking for! Thanks. Prefix it with Join@@ to match the spec.
    $endgroup$
    – Roman
    6 hours ago










  • $begingroup$
    @kglr, I never think of using Thread function before reading your answer. It's a little bit difficult for me to appreciate the mechanism of Thread. It's written "threads" f over any lists that appear in args in MMA's help page. But elements of l1 and l2 are both lists. I think Insert plays a role here so that the function only threads over element of l2. Am I understanding correctly? Thanks
    $endgroup$
    – Yaofeng
    5 hours ago










  • $begingroup$
    @Yaofeng, you are right for the first one. In the second, the second and third arguments of Thread controls what to thread over and in which positions.
    $endgroup$
    – kglr
    5 hours ago










  • $begingroup$
    @kglr, I compared the AbsoluteTiming for your Thread solution and Roman's Function solution. Yours is faster. Although it's not intuitive for me at the moment, but I guess that's the direction for me to go, in line with MMA's vectorization. Thanks again!
    $endgroup$
    – Yaofeng
    5 hours ago












  • 1




    $begingroup$
    Yes that's what I was looking for! Thanks. Prefix it with Join@@ to match the spec.
    $endgroup$
    – Roman
    6 hours ago










  • $begingroup$
    @kglr, I never think of using Thread function before reading your answer. It's a little bit difficult for me to appreciate the mechanism of Thread. It's written "threads" f over any lists that appear in args in MMA's help page. But elements of l1 and l2 are both lists. I think Insert plays a role here so that the function only threads over element of l2. Am I understanding correctly? Thanks
    $endgroup$
    – Yaofeng
    5 hours ago










  • $begingroup$
    @Yaofeng, you are right for the first one. In the second, the second and third arguments of Thread controls what to thread over and in which positions.
    $endgroup$
    – kglr
    5 hours ago










  • $begingroup$
    @kglr, I compared the AbsoluteTiming for your Thread solution and Roman's Function solution. Yours is faster. Although it's not intuitive for me at the moment, but I guess that's the direction for me to go, in line with MMA's vectorization. Thanks again!
    $endgroup$
    – Yaofeng
    5 hours ago







1




1




$begingroup$
Yes that's what I was looking for! Thanks. Prefix it with Join@@ to match the spec.
$endgroup$
– Roman
6 hours ago




$begingroup$
Yes that's what I was looking for! Thanks. Prefix it with Join@@ to match the spec.
$endgroup$
– Roman
6 hours ago












$begingroup$
@kglr, I never think of using Thread function before reading your answer. It's a little bit difficult for me to appreciate the mechanism of Thread. It's written "threads" f over any lists that appear in args in MMA's help page. But elements of l1 and l2 are both lists. I think Insert plays a role here so that the function only threads over element of l2. Am I understanding correctly? Thanks
$endgroup$
– Yaofeng
5 hours ago




$begingroup$
@kglr, I never think of using Thread function before reading your answer. It's a little bit difficult for me to appreciate the mechanism of Thread. It's written "threads" f over any lists that appear in args in MMA's help page. But elements of l1 and l2 are both lists. I think Insert plays a role here so that the function only threads over element of l2. Am I understanding correctly? Thanks
$endgroup$
– Yaofeng
5 hours ago












$begingroup$
@Yaofeng, you are right for the first one. In the second, the second and third arguments of Thread controls what to thread over and in which positions.
$endgroup$
– kglr
5 hours ago




$begingroup$
@Yaofeng, you are right for the first one. In the second, the second and third arguments of Thread controls what to thread over and in which positions.
$endgroup$
– kglr
5 hours ago












$begingroup$
@kglr, I compared the AbsoluteTiming for your Thread solution and Roman's Function solution. Yours is faster. Although it's not intuitive for me at the moment, but I guess that's the direction for me to go, in line with MMA's vectorization. Thanks again!
$endgroup$
– Yaofeng
5 hours ago




$begingroup$
@kglr, I compared the AbsoluteTiming for your Thread solution and Roman's Function solution. Yours is faster. Although it's not intuitive for me at the moment, but I guess that's the direction for me to go, in line with MMA's vectorization. Thanks again!
$endgroup$
– Yaofeng
5 hours ago

















draft saved

draft discarded
















































Thanks for contributing an answer to Mathematica Stack Exchange!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

Use MathJax to format equations. MathJax reference.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmathematica.stackexchange.com%2fquestions%2f200024%2fgenerate-certain-list-from-two-lists%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Invision Community Contents History See also References External links Navigation menuProprietaryinvisioncommunity.comIPS Community ForumsIPS Community Forumsthis blog entry"License Changes, IP.Board 3.4, and the Future""Interview -- Matt Mecham of Ibforums""CEO Invision Power Board, Matt Mecham Is a Liar, Thief!"IPB License Explanation 1.3, 1.3.1, 2.0, and 2.1ArchivedSecurity Fixes, Updates And Enhancements For IPB 1.3.1Archived"New Demo Accounts - Invision Power Services"the original"New Default Skin"the original"Invision Power Board 3.0.0 and Applications Released"the original"Archived copy"the original"Perpetual licenses being done away with""Release Notes - Invision Power Services""Introducing: IPS Community Suite 4!"Invision Community Release Notes

Canceling a color specificationRandomly assigning color to Graphics3D objects?Default color for Filling in Mathematica 9Coloring specific elements of sets with a prime modified order in an array plotHow to pick a color differing significantly from the colors already in a given color list?Detection of the text colorColor numbers based on their valueCan color schemes for use with ColorData include opacity specification?My dynamic color schemes

Tom Holland Mục lục Đầu đời và giáo dục | Sự nghiệp | Cuộc sống cá nhân | Phim tham gia | Giải thưởng và đề cử | Chú thích | Liên kết ngoài | Trình đơn chuyển hướngProfile“Person Details for Thomas Stanley Holland, "England and Wales Birth Registration Index, 1837-2008" — FamilySearch.org”"Meet Tom Holland... the 16-year-old star of The Impossible""Schoolboy actor Tom Holland finds himself in Oscar contention for role in tsunami drama"“Naomi Watts on the Prince William and Harry's reaction to her film about the late Princess Diana”lưu trữ"Holland and Pflueger Are West End's Two New 'Billy Elliots'""I'm so envious of my son, the movie star! British writer Dominic Holland's spent 20 years trying to crack Hollywood - but he's been beaten to it by a very unlikely rival"“Richard and Margaret Povey of Jersey, Channel Islands, UK: Information about Thomas Stanley Holland”"Tom Holland to play Billy Elliot""New Billy Elliot leaving the garage"Billy Elliot the Musical - Tom Holland - Billy"A Tale of four Billys: Tom Holland""The Feel Good Factor""Thames Christian College schoolboys join Myleene Klass for The Feelgood Factor""Government launches £600,000 arts bursaries pilot""BILLY's Chapman, Holland, Gardner & Jackson-Keen Visit Prime Minister""Elton John 'blown away' by Billy Elliot fifth birthday" (video with John's interview and fragments of Holland's performance)"First News interviews Arrietty's Tom Holland"“33rd Critics' Circle Film Awards winners”“National Board of Review Current Awards”Bản gốc"Ron Howard Whaling Tale 'In The Heart Of The Sea' Casts Tom Holland"“'Spider-Man' Finds Tom Holland to Star as New Web-Slinger”lưu trữ“Captain America: Civil War (2016)”“Film Review: ‘Captain America: Civil War’”lưu trữ“‘Captain America: Civil War’ review: Choose your own avenger”lưu trữ“The Lost City of Z reviews”“Sony Pictures and Marvel Studios Find Their 'Spider-Man' Star and Director”“‘Mary Magdalene’, ‘Current War’ & ‘Wind River’ Get 2017 Release Dates From Weinstein”“Lionsgate Unleashing Daisy Ridley & Tom Holland Starrer ‘Chaos Walking’ In Cannes”“PTA's 'Master' Leads Chicago Film Critics Nominations, UPDATED: Houston and Indiana Critics Nominations”“Nominaciones Goya 2013 Telecinco Cinema – ENG”“Jameson Empire Film Awards: Martin Freeman wins best actor for performance in The Hobbit”“34th Annual Young Artist Awards”Bản gốc“Teen Choice Awards 2016—Captain America: Civil War Leads Second Wave of Nominations”“BAFTA Film Award Nominations: ‘La La Land’ Leads Race”“Saturn Awards Nominations 2017: 'Rogue One,' 'Walking Dead' Lead”Tom HollandTom HollandTom HollandTom Hollandmedia.gettyimages.comWorldCat Identities300279794no20130442900000 0004 0355 42791085670554170004732cb16706349t(data)XX5557367