Replace at index in bidimensional lists

I need help replacing items in a multidimensional list… per screenshot.

Because of the -1 index I get the last item of the sublist to be replaced with the “null”…

Any idea? I just need the -1 indexes to leave the source list without replacements.

thanks

How are you creating the -1?

The -1 comes from the “ListIndexOf” node, when it does not find the element, the index is -1.
So, in the example, the node finds the elements requested only in the third and fourth sub-lists, but not the first and second, which return a -1.

The issue is not the -1, really, the issue is: how do I pass through UNCHANGED a list that has not indexes? Obviously the List.ReplaceItemAtIndex is still replacing the last item of the first and second sublists with Null…

thank you

You’re going down the street to dig out a rabbit hole to find a carrot instead of walking into the produce market.

You have a equally dimensioned list, with only good data values, so while what @erfajo showed may work (his stuff usually does), it’s not necessary so I haven’t tested it (in the Orchid package if you do want to test it).

Currently you are asking Dynamo to find a value in a list, pull it from the list, edit the value by adding the - suffix, and then put it back in the list where it was. Dynamo is telling you ‘well that value doesn’t exist here’ by putting in a null. You don’t want null as that will wind up back in your list (as you noticed). You could replace the null after you put the good value in the list, but you’re already doing all this work and still have a ways to go. And on a significant dataset all these tests and movements are going to tax your system and run slow.

So instead, why not try to ask dynamo to do something only IF something is true, otherwise just do something else (like pass on the original value).

You can do that with a single codeblock like this:
YourDataSet==YourTargets? YourDataSet+"-": YourDataSet;

Remember your if statement syntax. The ? is defining the end of your test, the : is defining the end of your thing if true, and the ; is defining the end of your line of code.

If you’re not up for an IF statement in a code block, you can do this with 4 nodes like so:

Personally I prefer the simplicity of the code block here, especially when it can be leveraged in conjunction with other operations (like your string from object node).