GroupByKey - lists as keys are not supported


#1

Using GroupByKey it is easy to group identical values:

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”.


#2

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.


#3

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.


#4

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.


#5

Use List@Level


#6


#7

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)


#8

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.


#9

@alvpickmans

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


#10

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