Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

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

I have two Lists names are list1 and list2

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

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?

share|improve this question
    
seems a bit contradictory... –  chris Dec 27 '12 at 10:52

2 Answers 2

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}.

share|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:

?list1

Global`list1

list1={a,b,c}

?a

Global`a

a=10

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.

step[list1]
 {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}]
share|improve this answer

Your Answer

 
discard

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.