Creating a list from 2 lists in Dynamo

Hi guys!
So, i’m trying to combine 2 lists in Dynamo, where 1 of the lists have priority over the other.

List 1: This list is full of values and I want these to be written to the new list except the ones covered in list 2.

List 2. This is a list that contains a few values, in a few places. These values have priority over List 1 values.

As you can see from my test, Only list 2 is written.

I tried fixing it with this code, but I get code error:


d = [Imperative] {
			for (i in ind)
				if (b[i] != null)
				return d[i] = b[i];
				} else {
				return d[i] = a[i];

Any suggestions?


A few quick points: Your values are not null, they’re just empty strings - your code is actually working correctly. That being said, don’t actually need to define an imperative function. Dynamo is pretty good at iterating through lists when using simple functions. You can do this in a code block pretty easily:


if b equal to [empty string] return a, else return b

1 Like

Are you kidding me. It was that easy? Thank you so much! <3

1 Like

You were really close. :wink:

It shouldn’t. You’re not making any changes to a or b. Can you show your graph?

It works now, I had an error with my outputs. :slightly_smiling_face:
Thank you so much!