GetItemAtIndex remove warning on empty list (custom node?)

thanks Jacob, uploaded screen capture along w/ Dynamo file FYI, seems
. only List.Map has correct result
. OOTB GetItemAtIndex@L1 has warning and wrong result
. Node to Code w/ conditional statement still has warning


for JacobSmall.dyn (21.4 KB)

Don’t make your life harder than you have to.

But since you asked about List.Map and Function.Apply, try this too:

thanks Jacob, L2 seems working OK but L1 is not, my previous test sample is L1 and index 1 instead of L2 and index 0, well, i’ll explore more in the future i.e. use beloved chatGPT to translate to Python

L1 won’t work as the data at L1 isn’t a list, but an individual object (ie: strings, integers) and List.GetItemAtIndex requires a list as the input.

2 Likes

i see, “must be a list” is the reason for warning of OOTB node, so no better way to avoid warning unless using traditional coding like Python w/ error checking and/or dirty try except, again, very appreciated for your help

@Level 2 should work in all cases; unless you’d have a list with variable depth structure, which is usually poor programming structure in any language.

1 Like

I guess I don’t follow what it is you’re trying to do. This isn’t something that python can fix. You can’t get an item at a specified index from an object that isn’t a list. It feels like you’re either missing some other condition or not understanding how list levels work.

Using the correct list levels will get you the output I think you’re looking for. However, it does return a warning because the index is out of range for some of your sublists (hence the null).

List.Map works because functions don’t pass list levels and List.Map is specifically meant to map to each sublist under the top level (the same as @L2 for this structure). Functions also don’t pass on warnings, so the nulls aren’t a problem in the output.

You can get around this by adding a preliminary check to ensure your sublists will have an item at that index first. If they do, return the value at that index. If they don’t, return a null.

2 Likes

thanks Nick, count works great!