Maintaining and managing list structure

OK, so i figured out what is happening.
“lenr” in the below, could be false.

Len_diff_Abs = Math.Abs((Lcr-lenr));

so you will have:
Math.Abs(someNumber - false)

This is confusing the Abs function. you’d think it will give a different error or warning message, since i am subtracting Boolean from integer or double.

Thanks for the help.
is there a better way to clean out nulls and strings of all kind from my input. i find what i did in the first 6 lines a bit awkward and lengthy :slight_smile:

1 Like

If you don’t care about the indices, you can ust List.Clean and a false value into the boolean optional input.

Thanks for the suggestion… but, although it gets rid of List.Empty and nulls, it does not get rid of empty strings… I ran into problems with those and that’s why i had those 3 lines in the code to filter them out.

1 Like

Do you need to keep your list structure? :slight_smile: Or can you flatten it before hand? Flattening the list will remove all Empty Lists, and you can then replace any empty string easily.

Otherwise, strategies will depend on the rank of your incoming data. Typically, scrubbing this, or “cleaning” it first will bring huge workflow benefit if you are able to :slight_smile:

1 Like

Hi Solamour,
is there a way to fork this last discussion into a new post… i should have done that from the get go, but …

regarding your last solution, i think it is easier to follow than my solution, albeit you need to know all that List.Flatten does. ( i did not know it takes care of List.empties).
But now, i am not sure how does this impact my code, since my other lists used in the code may have their issues on different location from the other lists, which means i may be doing my calculations on values from different location of the lists… is that what you meant with “if you don’t care about indices” in the earlier post?

@JacobSmall split it off for us (I need to learn how to do that :roll_eyes: ) so we can continue here!

Hi Solamour,
I have 2 questions:

  • Don’t you need to add list.flatten as an x input to the " ==" Node?
  • How do i write it as a designscript? i prefer that since it gives me real estate. I am not sure how to call “ReplaceByCondition”, and how do i enter its last parameter for the Bool condition.


Hi @fawzimasri7137,

  1. The ReplaceByCondition node requires the condition to be a function, which means you do not want to have the == node fully satisfied so that it sends through a function output. This is a little esoteric, but essentially you skip the X input and Dynamo fills in the blanks. It works as follows:

  1. Some nodes in Dynamo do not have any expression in DesignScript - and the ReplaceByCondition node is unfortunately one of them. You can either keep the node in the graph, or build your own version in a DesignScript definition.
1 Like

That’s exactly how i did it based on your first image. but then i could not figure out how that condition would relate to the list.flatten output. so i figured, it might need fed to the == node.

So what exactly is Dynamo “fills in the blanks” in the particular case?

i think i understand now… the value is not what is important here, it is the fact that we want the function “ReplaceByCondition” to use an equality condition vs other types of conditions.
i don’t understand how it works internally, but i think i can live with this for now.

1 Like

Functionally, we want to check the output of the List.Flatten node for a particular thing, in this case a false value. So we need to use the == node to check for that false value. Usually we would be connecting this up, but as the ReplaceByCondition node requires a function input, we have to use it in a function way :slight_smile:

Essentially, this means the ReplaceByCondition node will take in a list (item; List.Flatten output), parse through each item and check if it equals our match value of "" (Empty list in String form), and if so, then replace it with the chosen value of false.

It’s a bit funky to wrap your head around, but hopefully that helps paint the picture a little more.

thanks…for the explanation… yes it helps…

1 Like