0

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?

subbu
  • 2,304
  • 1
  • 13
  • 32

2 Answers2

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

m_goldberg
  • 107,779
  • 16
  • 103
  • 257
deltux
  • 55
  • 6
2

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}]
Mr.Wizard
  • 271,378
  • 34
  • 587
  • 1,371