Remove specified multiple sublists

Hello Dynamo community :slight_smile: . I have a problem, that i would like to remove sublists if it contains string inside named “Boundary”. (The lists contain different quantity of sublist that contain “Boundary” so this is why i want to make it more dynamic and this is the logic i came up with.)


image uploader



Thanks for the reply! I did the same too, but i want to remove the whole sublist that contains the string “Boundary” :slight_smile: .

That will remove the whole sublist. Just make sure the List.ContainsItem node has its lacing set to Longest.

1 Like

I want to keep the green sublists and remove the red sublists. Red contain “Boundary” strings…


I find its very useful to have a little Python knowledge when you encounter issues that Dynamo can’t handle directly.

Here you go :slight_smile: I wrote the code different for each loop, either works, just wanted to show there’s more than one way to check for a string with Python.

and the code:

1 Like

The correct answer is given by @Nick_Boyts in post 2.

but if you want to do it pythonic then do this
removeSublist.dyn (6.2 KB)

…the code

#input assigned the IN variable
elements = IN[0]
searchFor = IN[1]

#remove sublist
for idx, element in enumerate(elements):
    for elem in element:
        if elem == searchFor:

#output assigned the OUT variable
OUT = elements

Thank you for your time and patience. I did the same too, but the problem is that these lists are inside another list, so it’s not going to work. I even tried to use levels but it’s still giving me the wrong result. I hope this picture can help you to understand what i mean. I think that the solution is very close to this one.


upload images

well adjust the levels in the code or the nodes…
removeSublist.dyn (6.3 KB)

You need to keep the list structure when you use levels. It’ll work for any list size.

1 Like

It’s working with this idea. :smiley: I just needed to download clockwork. Thanks for the help, really appreciate it!!! :slight_smile:


i tried that too, but my dynamo gave me an error message… Thanks for the help!

It would be beneficial for you to learn about list levels. What @Nick_Boyts has shown from post two is the proper solution, and should be marked as the solution! What you do now is extra computation. If you work on larger dataset then you should always consider how to do it most efficient.