List which have subitems and sometimes not

Not sure how to explain my question which have bothered me for some hours now, but ill try anyway. The problem im having is that my dynamo script sometimes has a list with sub items, and sometimes not. When im using i can only get it to work on either cases, but not both. I bet there is an easy solution for this, but i cant seem to find it. See picture for both cases.

Case 1 (With sublist)

Case 2 (No sublist)
Could not add another image because im a new user.

Try using List Levels. Sometimes that will work for both.

Ive tried many different methods, both with levels, splitting the list and so forth. Can`t get it to work. Is it possible to create an if statement for whether a list has sublist or not?

Use your “string join” with lacing at @@lvl1, it’d go through as if it was a flat list and return it as it was fed.

Unless you just flatten the thing, but I guess you need them in sub lists.

I tried. It doesnt work. Maybe im doing something wrong, but i think i tried every possibility.

@Zschlave what exactly do you want your outcome to look like? A combination of the two images? :thinking:

When there are no sublist items i would like the outcome to be like this.

When there are sublist i want to List.Map the items in the sublist.

So if it’s a single item you want the Panel Name and if it’s 2 (or potentially more) items you want the concatenated circuit numbers?

Get both parameters from the list of elements. Then use an If statement to return either the panel name or the circuits depending on the length of the sublist.

1 Like

I have a sneaking suspicion that there is a point earlier in the graph where you zigged but could have zagged to make this easier on yourself. Can you post the full .dyn file?


@Zschlave Alter list structure by introducing a dummy?

StringJoin.dyn (9.4 KB)

I dont know how much you care about the list structure but @Dimitar_Venkov’s post in this thread shows how to normalize a list so you can have .map work on only one level.

I’ve made something that I think should work but it doesn’t…
I am working in version 0.9 however so it might work in a newer version.

Or maybe I’m an idiot and this simply shouldn’t work, I’d like to hear either way.

The if node has some interesting behavior.

I think both the true and false must be of the same size/level? Even when feeding it a single element vs a list of list, it automatically makes the single element a list of list of that one element.

Same thing if its a single element. When you make it a list before putting it into the true input, the single element false input is made into a list as well.

1 Like

Pretty odd.
I think it’s a shame as I guess it should work if it didn’t matter for that node.
Interesting to find out that there’s actually a need for consistency between the true and false inputs you give the If node. The reality is pretty annoying though.

1 Like

I have replied in another topic that was linking to this one. You can check it out:

Hello @kennyb6

You can try using ScopeIf instead of If. Look at the below graph, the results are correct with ScopeIf node.


Haven’t heard of that node before, thank you!


for i in IN[0]:
	if isinstance(i,list):
if x > 0:
	OUT ="It has at least a list"
	OUT ="No list found"


if IN[0] == "It has at least a list":
	OUT = IN[1]
elif IN[0] == "No list found":
	OUT = IN[2]

I dont like the IF nodes, I rather make my own and have expected behavior.
I know it could be shortened to a single script, but I find it clearer that way.

1 Like