回复:將附加值插入關聯數組中的現有鍵(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"}];高級統計建模數據混合和清理