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!