GroupByKey - lists as keys are not supported

Using GroupByKey it is easy to group identical values:

1dimlist

My problem is that I want to do the same for nested lists, meaning that I want to group nested lists that have the same values in it.
In the example below I want to group all the nested lists with the values “a,b,c,d” and create a group for all nested lists with the values “e,f,g”.
When I try to use GroupByKey I got the error “Lists as keys are not supported”.

One option would be to concatenate the content of the nested lists and use that as the grouping keys.

This assumes your nested lists are strings and are all in the same order or sorted.

1 Like

String from list works too and means you won’t need to convert other values to a string to concatenate. However you may want to convert the data to a comparable type (if they aren’t already) so you can sort it in case you have an {a,b,c} and a {b,a,c} list that you want to group as like.

Thanks all for your input. I hoped that there was another solution because in my real script I’m dealing with +20 of coordinate values in each nested list. Concatenating all these values together will make huge strings. I don’t know if this will affect performance and if there is a limits for sting lengths. Maybe I need to program a python script.

Use List@Level

Just for fun, I tried with a random list of 340k strings and takes around 10 seconds doing both group operations (sorted and unsorted). Maybe using python is faster, but is still a reasonable running time.

nestedStringListsGroup.dyn (21.4 KB)

1 Like

Hi John,

Thanks for your feedback. But even when I use levels the nested lists are not grouped.
In the image below, at the left side you see the results when using levels: each nested group stays a nested group. The right “Watch” node is showing what I want and what I simulated manually: each nested list with the same values is grouped together.

@alvpickmans

Thanks for spending time on it. This proves that I can indeed use this workflow.

Great! Please mark the topic as solved so it can be used as a future reference :slight_smile: