Group list by adjacent values

I have a list of y coordinates. I want to group points based on adjacent values. The list below would be broken up into two different lists.

106.8
107
107.2
107.4
107.6
120.4
120.6
120.8
121

Can you show your list in the graph?

This shows an example. I’m trying to group y values that have the same x value. I want to use this to get the min and max values but still have more than two points per x value if the points are broken by a wall like the image.

I don’t quite follow. What do you qualify as “adjacent”? If you want to group Y values with the same X coordinate then you should use GroupByKey. If you need to include some sort of “adjacency” you can round your values to your needed tolerance.

1 Like

I figured it out. I probably did it in my dumb not really a coder way. I’m already grouping the same X values. They python node gives each index a group number and then I count occurences to cut the list where to pattern of .2 feet is broken. I may rewrite it becuase it could just proved the list lengths directly, but when I wrote it I didn’t think thru how I would used the information.

you can use the itertools module with a divmod function

2 Likes