dict Merge Method

David Butler's icon

It doesn't seem like there is any way to add a new value to a key in a dictionary without removing all previous information. It would be great to be able to add information this way more easily, like the 'merge' method of coll. Is there any easy way to do this (without using loads of objects, or maintaining a separate coll?

kennethstewart's icon

Great question! I would very much like to know this as well.

Also, I'm curious if I can return just the data of a key without the key being prepended in its output.

K

kennethstewart's icon

Bump.

Is there a way in a dict to:

1. check if a key exists

(if it does...)

2a. simply append new data onto the array that is at that key's location

(if it does not...)

2b. put a key there with the new data

Ben Bracken's icon

Hi Kenneth,

Max Patch
Copy patch and select New From Clipboard in Max.

I've put in a feature request for this type of functionality with dict. In the meantime, you could do something like the below patch. Its a little clunky, but might work for you depending on what you need:

kennethstewart's icon

Nice. Thanks Ben. This will get me going for a while.

I'm curious about what's happening under the hood. If you use the temp dicts to nest other dicts like in the linked post by skeurid, would one be creating an efficiency problem down the line? What if one were to use several of those temp dicts at a time with thousands of data points of nested dicts, would there be a huge store of memory created? Or would the temp data simply vanish into the ether?

I'm sorry for my ignorance regarding garbage collection, but I just what to know more. Thanks. I'm sure this is similar to passing Jitter matrices by reference.

Ben Bracken's icon

I'm not entirely sure what you want to do, but if you are in JS, you can use the freepeer() JS method, like yourdict.freepeer() to free it.

-Ben