Compare tree branches and remove duplicated combinations

Hi everyone,

Im creating random combinations using 3 different formats - 300,400 and 500 and I need to remove duplicated combinations. I wonder if there is a good way to compare each tree branch from each data tree and remove duplicated combinations. Thank you in advance!

data_Tree_Remove duplicated (7.1 KB)

python code:

a = ["abc", "def", "ijk", "lmn", "opq", "rst", "xyz"]
b = ["ijk", "lmn", "opq", "rst", "123", "456" ]
for i in b[:]:
    if i in a:
>>> b
['123', '456']

now using this link you should be able to find a fast solution: Rhino - Grasshopper data trees and Python

another way is to comparing strings , combine your data in a row for example first item of list could be converted to this string:“300400500300400” and so on.
now you can get free from branches and then compare to next list.
hope this help.

Hi @saeed_hasan_zadeh,

Thank you for your feedback. I have been trying to get it to work and I end up with this.

I’m still very beginner in Python, so I’m a bit unsure if it is working properly. Looking at the code it seems to be but I’m not sure if the result is correct.
My first thoughts are at the correct output should be a list of branches common in both lists, but I’m getting none.

data_Tree_Remove duplicated (9.9 KB)

Get 6 takes on that matter (C# not P since I hate that thing). (119.6 KB)

Foreach option a classic Recursive LINQ Method is used (with or without repetitions blah, blah). For instance:

Hi! I have a similar problem, you can see the original post here: Python list comparison - #5 by akselalvarez

It seems that I don’t manage to feed the list into the script, since what I get is just two empty lists as result, but they preserve the same structure as my start list, therefore I think something may work.

I have a list that has several branches, each branch has 3 indices, I want to compare each branch so the values in the indices 1 and 2 are checked, if the two of them are repeated in another branch, then the complete branch will be placed in a list called “branches_duplicate”. If they don’t or are the first occurrence, they are to be placed in a list called “branches_unique”.

Until now it seems that I can print two lists, but they seem to be empty.

Here is my code:

# Provided list of branches
branches = []  # List of values from Model
branches_unique = []  # List to store branches with unique values at indices 1 and 2
branches_duplicate = []  # List to store branches with repeating values at indices 1 and 2

# Iterate through each branch
for branch in branches:
    seen_values = set()  # Keep track of unique values encountered in the current branch
    duplicate = False  # Flag to indicate if the branch has duplicate values
    # Check each element in the branch
    for i in range(1, 3):  # Check indices 1 and 2
        if branch[i] in seen_values:
            duplicate = True
    # Append the branch to the appropriate list
    if duplicate: