Mathematica Stack Exchange is a question and answer site for users of Mathematica. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Assume that I have two lists like :

list1={1,2,3,4,5}; list2={a,b,c,d,e};

I want to replace some elements from list1 into list2 and make a new list, NewList. For example, I want to replace the elements of list1 from position 1 and 5, with the elements of list2 with the same positions. The result will be :


Is there any way to do that ?!

share|improve this question
up vote 6 down vote accepted

Another way, doing it all at once:

Newlist = list2;    
Newlist[[{1,5}]] = list1[[{1,5}]];


   (* {1, b, c, d, 5} *)
share|improve this answer
It's a nice and easy method! Thank you. – Shellp Mar 31 '14 at 11:27
list1 = {1, 2, 3, 4, 5};
list2 = {a, b, c, d, e};

NewList = list2;
NewList[[1]] = list1[[1]];
NewList[[5]] = list1[[5]];

{1, b, c, d, 5}

share|improve this answer
Newlist = ReplacePart[#2, Rule @@@ Transpose[{#3, #1[[#3]]}]] &[list1, list2, {1, 5}]
share|improve this answer
Thank you !! That's great. – Shellp Mar 31 '14 at 11:26

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.