Setting a list as a dictionary value


Sorry if this is a stupid question, but I’m trying to create a dictionary for each list of items I have (e.g. each key value will have a list of items and not just one item per key). Please see attached for a simplified example. I need to generate the following from the list on the left:
0 Dictionary - Numbers in Set (0,1,2,3)
1 Dictionary - Numbers in Set (4,5)
2 Dictionary - Numbers in Set (6,7,8,9,10)

Any help with this list logic would be much appreciated.


I guess you need to convert your values to a string:

Is it what you were looking for?

Hi Luca,
I was hoping to store the items as a list, but if that isn’t possible then storing them as a string could work. This wouldn’t work for a group of point for example which seems very limiting for the dictionary function to not be able to store lists within each key.

Thanks for the quick response!

Create a second container list for each number list, so that the structure is like this:

(List.Chop with a length of 1 is a good way to do this with the data structure you presented)

Then use list levels and lacing like this:


@ryan.jones I was totally mistaken, I corrected my post, it is indeed possible to use lists as dictionaries values:


Nice @jacob.small! There is always something to learn, thanks!
However in your example it seems that multiple dictionaries are created, each one with a pair key-value. Would it be possible to have only one dictionary with multiple pairs?

Yes - I believe that a longer list of keys (as you provided in that design script example) would create that situation (but can’t test today - very busy).

Dictionaries can contain items, lists, dictionaries, and mixes of the three. I have an graph I am working on (nearly all design script) which has a dictionary containing a list that contains items (strings, a color, doubles and integers), a list of items (strings), and another dictionary that contains items (geometries) and a list of items (strings). May flatted the list into the base level of the last dictionary unless I find I need to add more data to the base level of that dictionary. Getting the value from the nested dictionary is tough (two nested value at key functions), but manageable if you’re careful with the coding.

1 Like

Thanks @lucamanzoni and @jacob.small - Really appreciate your help with this!