将元素附加到关联数组内的列表值你好,
我正在尝试将一个元素添加到关联数组中,其中值是一个列表,并且该元素需要添加到关联数组内的列表中。
例如:
卡里= [“高中”=> {“卡里”,“绿色希望”,“黑豹溪”},“人口”=> 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"}];