Sort a list by elements of another listOrdered indices of a multiple product or sumThe efficiency compare between Flatten[#, 1] & and Join @@ # &Lexicographic ordering of lists-of-lists?How-to select an entry from a list of pairs that meets a condition depending the 2nd element of each pairList of (sub-)lists - query sub-lists by names?Can we intelligently control evaluation in Thread?Sort list but keeping the number of swaps requiredFind positions in which list elements are equalHow can I check if elements between lists are equal?comparing lists of strings
Does "every" first-order theory have a finitely axiomatizable conservative extension?
Type int? vs type int
Was the picture area of a CRT a parallelogram (instead of a true rectangle)?
What to do with wrong results in talks?
Was Spock the First Vulcan in Starfleet?
Term for the "extreme-extension" version of a straw man fallacy?
Why not increase contact surface when reentering the atmosphere?
Is there a problem with hiding "forgot password" until it's needed?
How many times can American Tourist re-enter UK in same 6 month period?
How can a function with a hole (removable discontinuity) equal a function with no hole?
Why Were Madagascar and New Zealand Discovered So Late?
Did Dumbledore lie to Harry about how long he had James Potter's invisibility cloak when he was examining it? If so, why?
How can we prove that any integral in the set of non-elementary integrals cannot be expressed in the form of elementary functions?
Can I boil off chlorine? Does it evaporate quickly at high temperatures?
Are student evaluations of teaching assistants read by others in the faculty?
What is the difference between "behavior" and "behaviour"?
How do I go from 300 unfinished/half written blog posts, to published posts?
Is this version of a gravity generator feasible?
What is the best translation for "slot" in the context of multiplayer video games?
Is it okay for two “sein” to be next to each other?
If you attempt to grapple an opponent that you are hidden from, do they roll at disadvantage?
Is HostGator storing my password in plaintext?
Short story about space worker geeks who zone out by 'listening' to radiation from stars
What's this thing which looks like a water sensor inside a PC mouse?
Sort a list by elements of another list
Ordered indices of a multiple product or sumThe efficiency compare between Flatten[#, 1] & and Join @@ # &Lexicographic ordering of lists-of-lists?How-to select an entry from a list of pairs that meets a condition depending the 2nd element of each pairList of (sub-)lists - query sub-lists by names?Can we intelligently control evaluation in Thread?Sort list but keeping the number of swaps requiredFind positions in which list elements are equalHow can I check if elements between lists are equal?comparing lists of strings
$begingroup$
I know there are a plenty of other questions here which appear to be similar, however I did not found anything which could give me a hint.
I have to lists
list1=A,12,B,10,C,4; (*ordered according to the second column*)
list2=B,5,A,4,C,1; (*ordered according to the second column*)
Now I want to sort list2according to the list1-order so the output should be:
(*A,4,B,5,C,1*)
list-manipulation
$endgroup$
add a comment |
$begingroup$
I know there are a plenty of other questions here which appear to be similar, however I did not found anything which could give me a hint.
I have to lists
list1=A,12,B,10,C,4; (*ordered according to the second column*)
list2=B,5,A,4,C,1; (*ordered according to the second column*)
Now I want to sort list2according to the list1-order so the output should be:
(*A,4,B,5,C,1*)
list-manipulation
$endgroup$
$begingroup$
to be more specificlist2should be sorted according to the first column oflist1
$endgroup$
– M.A.
1 hour ago
add a comment |
$begingroup$
I know there are a plenty of other questions here which appear to be similar, however I did not found anything which could give me a hint.
I have to lists
list1=A,12,B,10,C,4; (*ordered according to the second column*)
list2=B,5,A,4,C,1; (*ordered according to the second column*)
Now I want to sort list2according to the list1-order so the output should be:
(*A,4,B,5,C,1*)
list-manipulation
$endgroup$
I know there are a plenty of other questions here which appear to be similar, however I did not found anything which could give me a hint.
I have to lists
list1=A,12,B,10,C,4; (*ordered according to the second column*)
list2=B,5,A,4,C,1; (*ordered according to the second column*)
Now I want to sort list2according to the list1-order so the output should be:
(*A,4,B,5,C,1*)
list-manipulation
list-manipulation
asked 1 hour ago
M.A.M.A.
545
545
$begingroup$
to be more specificlist2should be sorted according to the first column oflist1
$endgroup$
– M.A.
1 hour ago
add a comment |
$begingroup$
to be more specificlist2should be sorted according to the first column oflist1
$endgroup$
– M.A.
1 hour ago
$begingroup$
to be more specific
list2should be sorted according to the first column of list1$endgroup$
– M.A.
1 hour ago
$begingroup$
to be more specific
list2should be sorted according to the first column of list1$endgroup$
– M.A.
1 hour ago
add a comment |
2 Answers
2
active
oldest
votes
$begingroup$
idx = Lookup[
AssociationThread[list1[[All, 1]] -> Range[Length[list1]]],
list2[[All, 1]]
];
list2[[idx]]
A, 4, B, 5, C, 1
$endgroup$
add a comment |
$begingroup$
Permute[list2, FindPermutation[ list1[[All,1]] , list2[[All,1]] ] ]
A, 4, B, 5, C, 1
$endgroup$
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
return StackExchange.using("mathjaxEditing", function ()
StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix)
StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["$", "$"], ["\\(","\\)"]]);
);
);
, "mathjax-editing");
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
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e)
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom))
StackExchange.using('gps', function() StackExchange.gps.track('embedded_signup_form.view', location: 'question_page' ); );
$window.unbind('scroll', onScroll);
;
$window.on('scroll', onScroll);
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmathematica.stackexchange.com%2fquestions%2f194061%2fsort-a-list-by-elements-of-another-list%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
$begingroup$
idx = Lookup[
AssociationThread[list1[[All, 1]] -> Range[Length[list1]]],
list2[[All, 1]]
];
list2[[idx]]
A, 4, B, 5, C, 1
$endgroup$
add a comment |
$begingroup$
idx = Lookup[
AssociationThread[list1[[All, 1]] -> Range[Length[list1]]],
list2[[All, 1]]
];
list2[[idx]]
A, 4, B, 5, C, 1
$endgroup$
add a comment |
$begingroup$
idx = Lookup[
AssociationThread[list1[[All, 1]] -> Range[Length[list1]]],
list2[[All, 1]]
];
list2[[idx]]
A, 4, B, 5, C, 1
$endgroup$
idx = Lookup[
AssociationThread[list1[[All, 1]] -> Range[Length[list1]]],
list2[[All, 1]]
];
list2[[idx]]
A, 4, B, 5, C, 1
edited 1 hour ago
answered 1 hour ago
Henrik SchumacherHenrik Schumacher
58.1k580160
58.1k580160
add a comment |
add a comment |
$begingroup$
Permute[list2, FindPermutation[ list1[[All,1]] , list2[[All,1]] ] ]
A, 4, B, 5, C, 1
$endgroup$
add a comment |
$begingroup$
Permute[list2, FindPermutation[ list1[[All,1]] , list2[[All,1]] ] ]
A, 4, B, 5, C, 1
$endgroup$
add a comment |
$begingroup$
Permute[list2, FindPermutation[ list1[[All,1]] , list2[[All,1]] ] ]
A, 4, B, 5, C, 1
$endgroup$
Permute[list2, FindPermutation[ list1[[All,1]] , list2[[All,1]] ] ]
A, 4, B, 5, C, 1
answered 11 mins ago
MikeYMikeY
3,473714
3,473714
add a comment |
add a comment |
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e)
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom))
StackExchange.using('gps', function() StackExchange.gps.track('embedded_signup_form.view', location: 'question_page' ); );
$window.unbind('scroll', onScroll);
;
$window.on('scroll', onScroll);
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmathematica.stackexchange.com%2fquestions%2f194061%2fsort-a-list-by-elements-of-another-list%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e)
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom))
StackExchange.using('gps', function() StackExchange.gps.track('embedded_signup_form.view', location: 'question_page' ); );
$window.unbind('scroll', onScroll);
;
$window.on('scroll', onScroll);
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e)
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom))
StackExchange.using('gps', function() StackExchange.gps.track('embedded_signup_form.view', location: 'question_page' ); );
$window.unbind('scroll', onScroll);
;
$window.on('scroll', onScroll);
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e)
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom))
StackExchange.using('gps', function() StackExchange.gps.track('embedded_signup_form.view', location: 'question_page' ); );
$window.unbind('scroll', onScroll);
;
$window.on('scroll', onScroll);
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
$begingroup$
to be more specific
list2should be sorted according to the first column oflist1$endgroup$
– M.A.
1 hour ago