I don't know this is correct question or not,but I have a doubt.

I have two Lists names are list1 and list2


I want to assign Part[list2,1] value (10) to the Part[list1,1].that means Part[list1,1] act as Variable.

after assigning,

If I evaluate list1,it will shows {a,b,c},

if I evaluate list2,it will shows {10,20,30}.

if I evaluate a,it will shows 10.

I want like this..

Is it possible like this?

  • $\begingroup$ seems a bit contradictory... $\endgroup$ – chris Dec 27 '12 at 10:52

You can do a direct assignment:

{a, b, c} = {1, 2, 3}

Then, a will return 1, b will return 2 and so on. However, {a,b,c} will return {1,2,3}.

| improve this answer | |

This general topic has been covered in Assigning values to a list of variable names and the questions linked below it.

Within the normal syntax of Mathematica you will need a Hold or similar device to achieve your objective. Depending on your actual use you will need to select between a number of different methods and compromises.

Understand that {a,b,c} cannot be returned raw if a, b, and c have values assigned or you will see the values instead. To illustrate, you can make the assignments like this:

ClearAll[a, b, c, list1, list2];

list1 = {a, b, c};
list2 = {10, 20, 30};

Evaluate[list1] = list2;

And you can confirm them:







But when you retrieve the value of list1 you get {10, 20, 30} because a, b, and c evaluate.

Previously I wrote step to conveniently recover such intermediate definitions.

 {a, b, c}

This is wrapped in HoldForm to display these symbols without further evaluation, as can be seen with:

step[list1] // InputForm
HoldForm[{a, b, c}]
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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