List which have subitems and sometimes not


#1

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 list.map 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.
Link: https://imgur.com/a/A6Vug


Different inputs for an "IF" node issue
#2

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


#3

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?


#4

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.


#5

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


#6

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


#7

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


#8

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


#9

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.


#10

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?


#11

@Zschlave Alter list structure by introducing a dummy?


StringJoin.dyn (9.4 KB)


#12

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.


#13

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.


#14

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.


#15

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.


#16

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.


#17

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


#18

Hello @kennyb6

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


#19

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


#20

♪♫♪♫ 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.