Remove duplicates from list after extracting items from list

Hi all,

I have a list where I would like to extract first items from every branch but if first item is same as item extracted before then extract next item. Please help.

duplicates.gh (10.1 KB)

It’s not an easy thing to do in grasshopper, maybe using C# or Python makes it easier.

private void RunScript(DataTree<int> x, ref object A)
  {
    List<int> nums = new List<int>();
    foreach(List<int> branch in x.Branches)
      foreach(int i in branch)
        if(!nums.Contains(i))
        {
          nums.Add(i);
          break;
        }
    A = nums;
  }

Greatsaiyamandbz.gh (15.8 KB)

4 Likes

Awesome work. You are from Utopia (advance civilization)

fyi: python version looks like this:

a=[]
for branch in x.Branches:
    for i in branch:
        if not i in a:
            a.append(i)
            break
1 Like

Thank you very much for your algorithms. Is it possible to make this loop in clean manner without hoopsnake. So either in c# or python/ Kindly see the gh file

.duplicates-loop.gh (13.9 KB)

here same method as above… Keep adding next number in list where duplicates from other branch is not considered.

You can use loop

duplicates _loop.gh (15.2 KB)

Thank you I really appreciate your work. But I need the numbers to add up in same branch and those numbers should not be repetitive like I have values with panels at end.

are you doing this more than once?
if not maybe this also works :slight_smile:

Thank you for the definition. But I am doing it more than once. Once first items of each branch is extracted, the loop starts with extracting the next item from each branch and continues until all numbers are extracted from list. All by not repeating same numbers.

1 Like