將元素附加到關聯數組內的列表值你好,
我正在嘗試將一個元素添加到關聯數組中,其中值是一個列表,並且該元素需要添加到關聯數組內的列表中。
例如:
卡里= [“高中”=> {“卡里”,“綠色希望”,“黑豹溪”},“人口”=> 116244,“州”=>“北卡羅來納州”,“天氣”=> 「晴朗」] ;
在這之中,
1. 如何為「高中」清單新增條目?
2. 如何將「天氣」值轉換為清單?即“天氣”=> {“晴天”,“潮濕”}
非常感謝任何有關此問題的幫助。
謝謝,
迪利普
回覆:將元素附加到關聯數組內的列表值JSL 通常有不只一種方法。 這是我的方法:
cary = ["high schools" => {"Cary", "Green Hope", "Panther Creek"}, "population" => 116244, "state" => "NC", "weather" => "sunny"];
Insert Into( cary["high schools"], "Black Bear" );
cary["weather"] = { "sunny", "humid" };
我確信具體細節將決定在這種情況下哪種方式最適合您。
回覆:將元素附加到關聯數組內的列表值可能有一種更簡單的方法,但下面的方法似乎可行。
cary = ["high schools" => {"Cary", "Green Hope", "Panther Creek"}, "population" => 116244,
"state" => "NC",
"weather" => "sunny"];
// 1.
cary << Insert("high schools", Insert(cary["high schools"], "another school"));
// 2.
cary << Insert("weather", Eval List(Insert(List(cary["weather"]), "humid")));
Show(cary);
/*:
cary = ["high schools" => {"Cary", "Green Hope", "Panther Creek", "another school"}, "population" => 116244, "state" => "NC", "weather" => {"sunny", "humid"}];