Comparing Sublists within Same List

Hello Again Wizards,

I am trying and failing to find a way to compare sublists. I am using a bounding box list to get all locations of overlapping lines. Yet, when running through the list, there are locations where the same coordinates are contained within other smaller lines as well as the larger length coordinates. So what i would like to do is find a way to compare an entire sublist to other entire sublists in the same list to see if duplicates occur.You can see in image that on top list there is a sublist (0 List) which contains 6 points where lines overlap, but those same points all also occur in the lower list (29 List) where there are 7 points. Is there a way to check this and then remove the original sublist which is contained in another sublist?

Are you only wanting to compare entire sublists? If sublist0 has 7 items and sublist1 contains 6 items, only 5 of which are contained in sublist0, would you remove just those 5 items or only if the entire sublist was contained? If it’s the latter, would that only be if all the duplicate items are contained in one single sublist or even if the duplicates were split between two other sublists?

I think we need more clarification on what you’re after. What are you starting with? How are you getting to these sublists? What counts as a duplicate and what doesn’t?

It’s sounding like you’ll have to compare each sublist individually and maintain all those lists of comparisons in parallel until you clean up the duplicates. There may be an easier way depending on the rest of your logic though.

Ultimately yes I would like to compare the sub lists and remove only the duplicate line points if all items in sublist exist in another sublist. So in the example lists I would like to remove the entire top list being it’s contained in the lower list. I think there will be occasions where points will exist in multiple sublists. But being the entire sublist won’t exist in another then I don’t think I will need to worry about that.

These lists come from a bounding box node where I am getting all the occurrences of overlapping lines. So the comparisons will all be contained within one list to basically compare to the same list. I have values associated to the lines so at the end, I will get a list of values that I can add together and will not have any duplicates.

It would be best if we could see your full graph to have a better idea of what it is you’re doing.

Beyond that, all you can do is compare the lists one at a time and check for a full list of similar values (something like List.AllTrue).

@dweber12 have you tried List.SetDifference node?
If you’re trying to compare for coincident lines then that will require some maths

Here is a snap shot of nodes prior to those watch list nodes i attached earlier. I have a huge graph prior to this area doing other things and this part is the final piece i need to get what i am looking for. I am trying to get a list of points from lines which overlap one another. Ultimately at the end, i will use those points to split the longer lines and take the values associated with those lines to merge and add together. Hence why i am trying to remove the sublists which coordinates are also completely in another sublist.

I think it will do the job.

@NIRMAL Using this option just gives me an entire list of empty lists. Using SetDifference i would need to have two lists to compare when in reality i am comparing all the lists within the same overall list. Unless there is a way to make this work?

Image shown here is the same overall “list” just different indexes. But you can see that all items in 0 list also occur in 29 list. I ultimately want to remove 0 list being the entire list exists with the 29 list.

You should try it at @L2 based on the image you shared in this post.

image

I have tried this prior but still get empty lists. I am thinking the issue is that its the same list comparing to itself so there shouldn’t technically be any differences.

try connecting like this.

same empty list results. doesn’t comparing a list to itself mean there will be no differences?

If you can share your Graph and Revit file here then do so. I tested it on a sample, and it’s functioning well. The only requirement is that List1 should contain more items than List2 in order to calculate the difference.

edit:

Thats the issue. The lists i am comparing are the same list. I want to compare the lists within an overall list. I need to compare each sublist to each other within the overall list to see if any sublist values are in another sublist as shown in example images i had.

Without seeing the data being compared, it’s difficult to provide a clear answer.
The image you shared doesn’t display items from the same index in List1 and List2. The logic is straightforward: if all items in a sublist of List1 are found in the corresponding sublist of List2, the result will be an empty list.

The lists i showed are coming from the same original node.

I was trying to give an example where all the items in 0 list also occur in 29 list. The two watch nodes come from the same place. So what i want to accomplish is to compare each sublist to the other sublists to see if the all the values in the a sublist also occur in another.

This statement is confusing.

To find common elements between sublists of List1 and their corresponding sublists in List2, you can use List.SetIntersection in a similar manner.

Understood. Utilize the “Get Item at Index” to extract the lists at indexes 0 and 29. Then, connect these to “List.SetDifference” to obtain the desired output.
And you need simplify and determine the logic to get those indexes automatically if you want to use the script for n number of times or in different models. so that it identifies which index it has to take for comparison.

Check if the example below (Lines replaced by strings) captures your problem

a = List.UniqueItems(List.TakeItems(List.Chop(List.Shuffle(List.Cycle("a".."k",3)),[5,3,1,6,2]),5));
c = List.Count(a<1>);
d = List.IndexOf(List.Flatten(a,-1),a);
e = List.Flatten(d,-1) >= 0..(Math.Sum(c)-1);
f = List.FilterByBoolMask(a,List.Chop(e,c))["in"];
1 Like

What is it that you’re ultimately trying to do? What is the problem you’re trying to solve? Why are you needing to find intersection points and group them for duplicates? It looks like you’re trying to clean up boundary lines. If you can explain to us what your design process is here then we might be able to offer a better solution.

To check your sublists for fully contained duplicates you’ll have to:

  1. Compare each sublist against every other sublist.
  2. Check to see if the full sublist contains all matches (AllTrue).
  3. Check to make sure the original list length is equal to the boolean list length. (Checking against a shorter list will return a shorter result, ignoring additional values.)
  4. Check that 2 and 3 are both true.
  5. Remove the sublist at the search index. (List0 compared to List0 will always be a match so we remove that evaluation from the resultant list so that we don’t end up with all empty lists.)

Python would likely be easiest but it should be possible with nodes as well.