回复:将附加值插入关联数组中的现有键(JSL 中的数据字典)对待价值前[“b”]像任何其他列表一样。
Names Default To Here( 1 );
ex = Associative Array();
ex["a"] = {"10"};
ex["b"] = {"20"};
ex["c"] = {"30"};
// Add new value to "b"
Insert Into( ex["b"], {"21"} );
Show( ex );回复:将附加值插入关联数组中的现有键(JSL 中的数据字典)马克的答案是最好的。 你也可以这样做
ex["c"][nitems(ex["c"])+1]="99";
这是更丑陋,更慢,更不简洁。 但它可能暗示其他可能性。 列表有一个很酷的 one-beyond-the-end 下标属性,允许通过一个元素扩展列表。
回复:将附加值插入关联数组中的现有键(JSL 中的数据字典)我实际上正在使用更像这样的东西,所以我想我缺少对变量的评估:
Names Default To Here( 1 );
ex = Associative Array();
a_s = "a";
b_s = "b";
c_s = "c";
a_n = "10";
b_n = "20";
c_n = "30";
ex[a_s] = {a_n};
ex[b_s] = {b_n};
ex[c_s] = {c_n};
// Add new value to "b"
b_n = "21";
Insert Into( ex[b_s], {b_n} );
Show( ex );
// ex = ["a" => {a_n}, "b" => {b_n, b_n}, "c" => {c_n}];
回复:将附加值插入关联数组中的现有键(JSL 中的数据字典)列表的定义表明它们没有被评估。
列表:创建项目列表而不评估它们。
只需将它们包装在 evallist() 中
Names Default To Here( 1 );
ex = Associative Array();
a_s = "a";
b_s = "b";
c_s = "c";
a_n = "10";
b_n = "20";
c_n = "30";
ex[a_s] = Evallist({a_n});
ex[b_s] = Evallist({b_n});
ex[c_s] = Evallist({c_n});
// Add new value to "b"
b_n = "21";
Insert Into( ex[b_s], Evallist({b_n}) );<BR />// or you could this it seems easier.
// Insert Into( ex[b_s], b_n) ;<BR />
Show( ex );回复:将附加值插入关联数组中的现有键(JSL 中的数据字典)这行得通,但是如果给定的键不存在,那么我就无法向其中插入新元素。
不管键是否已经存在,是否有一种简单的方法来引入新键-->值或插入新值?
回复:将附加值插入关联数组中的现有键(JSL 中的数据字典)我认为您需要使用 if 语句来检查密钥是否存在,如果不存在则创建它。 我通常通过用一个空列表创建它来做到这一点,然后进入将新元素添加到现有列表的代码。回复:将附加值插入关联数组中的现有键(JSL 中的数据字典)完整的例子,包括明显的这样做的方式不是正常工作。
// I wish the default value for AA's worked correctly with a list for the
// default, but it does not:
aa = [=> {}];
Insert Into( aa["fred"], 1 );
Insert Into( aa["ralph"], 2 );
Show( aa ); // aa = [=> {1, 2}]; ?!?!?!?!
// so you must do an explicit test and create the key/list like this:
aa = [=> ];
For( i = 1, i <= 3, i += 1,
For Each( {key}, {"fred", "ralph"},
If( !(aa << Contains( key )), // key does not exist?
aa[key] = {};// add the key with an empty list
);
Insert Into( aa[key], i );// insert into list
)
);
Show( aa ); // aa = ["fred" => {1, 2, 3}, "ralph" => {1, 2, 3}];
将附加值插入关联数组(JSL 中的数据字典)中的现有键我找不到向关联数组中的现有键添加新值的正确方法。
Names Default To Here( 1 );
ex = Associative Array();
ex["a"] = {"10"};
ex["b"] = {"20"};
ex["c"] = {"30"};
<BR />// Add new value to "b"
ex["b"] = {"21"};
show(ex);
//ex = ["a" => {"10"}, "b" => {"21"}, "c" => {"30"}];
// Solution needed
//ex = ["a" => {"10"}, "b" => {"20", "21"}, "c" => {"30"}];高级统计建模数据混合和清理