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


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:














Please help, thanks :slight_smile:


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



Have you tried the SetIntersection node?




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




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



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



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


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



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