nightTrevors
nightTrevors

Reputation: 649

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

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)

Upvotes: 1

Views: 2324

Answers (1)

terrylynch
terrylynch

Reputation: 13572

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)

Upvotes: 2

Related Questions