Trying to recursively subtract one List's items from another List


#1

I’m trying to develop a way of removing List A from List B, such that the result is “any item in List B that does not have an equivalent in List A”. I have a feeling that current nodes out there find all equal values and remove them at once. If there are 4 values in List B “apples,apples,pears,pears” and 2 values in List B “apples,pears”, I want the output to be “apples,pears” - because two of those items are unaccounted for in the subtraction list. In other words, actual ‘count’ of item results is important, not just the values themselves.

Okay, so I have tried with recursion but I can’t get it working. See below for my current work:

recursionnode

 

 

 

 

 

recursiondyn

 

 

 

 

 

 

Please help, thanks :slight_smile:


#2

I got what I wanted in Python, I will publish eventually in Bakery package:

pythonanswer


#3

Have you tried the SetIntersection node?

20150714-1

 


#4

I’m not too sure if this does what you want. But it is in Rhythm.

2015-07-14_07h31_27


#5

Luke,

My earlier response wasn’t what you were looking for, I realized.

I suppose the Design Script code I’ve attached below should do what you are trying to achieve. (“actual ‘count’ of item results is important, not just the values themselves”)

File: Remove InstancesFromList.dyn

20150715-1


#6

@John - A similar result is obtained by using the SetDifference node


#7

Vikram,

Thanks for your designscript example, it does work and gets a similar result to the Python version I showed above.

However, I cannot get it working in a custom node. I am running 0.8.0 and when I add the function to the custom node as per image below, Dynamo essentially just stalls ‘not responding’. Am I doing this wrong?

not working as node


#8

Luke - Might have something to do with ‘from’ in your Input node.

Node file (created in Dynamo Studio, so the version is 0.8.0): RemoveList Instances.dyf

20150716-1


#9

I had a problem with the login screen for a few days. Here’s another way that can get into nested lists…
recursion