Merging two values in data tree

Hello, i have data of lines and their length, divided into branches. I want to join data from one branch to another under condition that the length of line is bigger/smaller than average.
So for example in my screenshot, that would be like 8.186056 (1;17) in one branch, and then 330,541717 342,423254 (1;18),(1;19) merged to one branch so that would be two numbers under one branch (1;18). The next branch (1;20) should become (1;19) etc…

How about using the python token (name: python 3 script) to solve the problem? If you can’t programm python; try to let Chat GPT programm the code for you… Chat GPT is quite well in handeling minor coding problems…

you mean that values in 2 consecutive branches must both be exclusively bigger than data-tree average in order to be both merged in the same branch?

yes, exactly. Also i still don’t know how to do it in python hahaha

I can try to programm if in python for you. but I don’t really get what you want. :wink:
the task the way I understand it:

  1. You have a list of numbers.
  2. Find the average of all the numbers in the list.
  3. Go through the list: if two numbers next to each other are both greater than the average, combine them into a single group (branch).
  4. Create a new list: it should have all the original numbers, but any high numbers grouped together should now be in branches (like [number], [high number, high number], [number])

do I understand it correctly?
what if there is just one or three high number(s)?

Yes, exactly that is what i meant, thank you in advance.

there are always even number of numbers greater than the average

to the number 3.
if "two numbers next to each other are both greater than the average, combine them into a single group (branch)" ,
But if one number is smaller than average put just one into branch

so that would be:

single number in branch (number is smaller than average)

two numbers in branch(both are greater than the average)

just like that till the end of list

Filip Pawlicki_2.gh (10.8 KB)