How to append a single element to a list keyed in a dict

2.1k views Asked by At

If I have

dict:`a`b!(1 2 3;4 5 6 7)

Can I append an element to dict`b without redeclaring the whole dict?

ie what's the best way to get to

dict:`a`b!(1 2 3;4 5 6 7 8)
1

There are 1 answers

0
terrylynch On BEST ANSWER

You can do

dict[`b],:8

but it will automatically overwrite the dictionary.

A more robust way would be

@[dict;`b;,;8]

or

 @[`dict;`b;,;8]

where the latter automatically overwrites the dictionary, while the former creates a modified copy of the dictionary (in case you don't want it to overwrite the original yet)