List which have subitems and sometimes not

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?

2 Likes

@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.

3 Likes

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

♪♫♪♫ I AIN’T THE SHARPEST TOOL IN THE SHED ♪♫♪♫

x=0
for i in IN[0]:
	if isinstance(i,list):
		x+=1
	else:
		x+=0
		
if x > 0:
	OUT ="It has at least a list"
else:
	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]
else:
	OUT = "FEED ME DATA"

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

Here is the link to the .dyn file.

I think i now got it to work by adding a list.chop and list.count in front of some list.filter by boolean. Thanks for all the replies pointing me in the right direction:)