cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Choose Language Hide Translation Bar
miguello
Level VI

Associative Array from variables

Can somebody help me with a correct syntax  to create Associative Array from variables?

Now I have this:

 

a = {"a1", "a2", "a3"};
b = {"b1", "b2", "b3"};

AB = [
	"AA" => a,
	"BB" => b
];

AB["AA"];

It returns:

 

/*:

a

I want it to return:

/*:

{"a1", "a2", "a3"}

I tried different combinations of Eval List(), Eval Expr(), Expr() and Eval(), but no luck.

 

Thanks!

 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
ErraticAttack
Level VI

Re: Associative Array from variables

You almost had it!  You need to input the arguments to Associative Array() as Associative Array( keys, values ), instead of Associative Array( {keys, values} ),

 

a = {"a1", "a2", "a3"};
b = {"b1", "b2", "b3"};


keys = {"AA", "BB"};
values = Eval List({a, b});


AB = Associative Array(keys, values);

AB["AA"];
Jordan

View solution in original post

4 REPLIES 4
Jasean
Staff

Re: Associative Array from variables

AB = Associative Array(EvalList({a, b}))
miguello
Level VI

Re: Associative Array from variables

This does not produce the desired result. Keep in mind, keys are "AA" and "BB", and values for those keys are lists a and b, respectively.

But it got me on the correct track, so this works as intended:

a = {"a1", "a2", "a3"};
b = {"b1", "b2", "b3"};


keys = {"AA", "BB"};
values = Eval List({a, b});


AB = Associative Array({keys, values});

AB["AA"];

Thanks!

 

P.S. Actually it doesn't work either.

 

I can't understand how JMP decides which one to use if my values are lists too??

//Create an associative array from a list that contains two lists of a key-value pair:

map = Associative Array( {{"yes", 0}, {"no", 1}} );

//Create an associative array from a list of keys and a list of values:

map = Associative Array( {"yes", "no"}, {0, 1} );

 

miguello
Level VI

Re: Associative Array from variables

Had to go brute force way for now:

 

AB = Associative Array();
AB["AA"] = Eval List(a);
AB["BB"] = Eval List(b);
ErraticAttack
Level VI

Re: Associative Array from variables

You almost had it!  You need to input the arguments to Associative Array() as Associative Array( keys, values ), instead of Associative Array( {keys, values} ),

 

a = {"a1", "a2", "a3"};
b = {"b1", "b2", "b3"};


keys = {"AA", "BB"};
values = Eval List({a, b});


AB = Associative Array(keys, values);

AB["AA"];
Jordan