Grouping consecutive similar values

Hello folks,

I have a list of parameter values, and I’d like to group them into sub-lists if they are similar AND consecutive. I’m partway there with Group By Function, but the consecutive part is throwing me for a loop.

Backstory: Users will be selecting a series of items to apply item numbers. If they select multiple of the same equipment IN A ROW those items will get the same number, however that same piece of equipment selected later will not (see list 2 vs list 5 in the attached screenshot). If there’s a better way to go about this than the path I’m on, I’m open to those suggestions as well.

Thanks,

Hi @TravisJ ,
Welcome to the Dynamo community.
I understand that you might have just jumped on the Dynamo train and might not be well-versed with Python. But see if this help:

from itertools import groupby
OUT = [list(groups) for keyValue,groups in groupby(IN[0])]
1 Like

My Python skills are unfortunately nearly non-existent, but I can copy and paste with the best of them. That grouped my parameter values perfectly, and I was able to use the solution in the thread below to apply the grouping to my original list of elements. Thanks for your quick help.

https://forum.dynamobim.com/t/change-list-structure-to-match-another-list-structure/27451/8

1 Like