# List control, Combine two lists with lots of Nulls but some information

**URL:** <https://forum.dynamobim.com/t/list-control-combine-two-lists-with-lots-of-nulls-but-some-information/34224>\
**Category:** Revit\
**Tags:** revit, dynamo, list-filter\
**Created:** [April 1, 2019, 9:55am UTC](https://forum.dynamobim.com/t/list-control-combine-two-lists-with-lots-of-nulls-but-some-information/34224 "2019-04-01T09:55:20Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![jonny.pye](https://avatars.discourse-cdn.com/v4/letter/j/3e96dc/32.png) [@jonny.pye](https://forum.dynamobim.com/u/jonny.pye)\
**Post date:** [April 1, 2019, 9:55am UTC](https://forum.dynamobim.com/t/list-control-combine-two-lists-with-lots-of-nulls-but-some-information/34224/1 "2019-04-01T09:55:20Z")

</div>

Hi, I have two lists of 23.

The first list contains the information I need in the first 4 of the list as shown with the rest as Nulls.

The second List contains the information I need but from 17-22 in the list.

I would like a resulting list of 23 with the information i need in one list of 23.

 ![image](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/9/2/924e2034b74d3ba0e0300aeeb30725cee449d9a9.png)

Doesy anybody know how I might do this?

---

<div class="post-metadata">

**Author:** ![Johannes\_Meiners](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/johannes_meiners/32/9156_2.png) [@Johannes\_Meiners](https://forum.dynamobim.com/u/Johannes_Meiners)\
**Post date:** [April 1, 2019, 10:08am UTC](https://forum.dynamobim.com/t/list-control-combine-two-lists-with-lots-of-nulls-but-some-information/34224/2 "2019-04-01T10:08:12Z")

</div>

Try this way:

 ![list-merge](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/5/4/54ed8fc82863d0f08f4866465d97575b11cf599f.png)

---

<div class="post-metadata">

**Author:** ![jonny.pye](https://avatars.discourse-cdn.com/v4/letter/j/3e96dc/32.png) [@jonny.pye](https://forum.dynamobim.com/u/jonny.pye)\
**Post date:** [April 1, 2019, 10:35am UTC](https://forum.dynamobim.com/t/list-control-combine-two-lists-with-lots-of-nulls-but-some-information/34224/3 "2019-04-01T10:35:45Z")

</div>

Thanks for the reply, the list format i’m looking for is slightly different. Hopefully the below list explains better.

 ![image](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/d/f/dfe2bc3e60345ae33352cf967577b040f5aa2f97.png)

---

<div class="post-metadata">

**Author:** ![Johannes\_Meiners](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/johannes_meiners/32/9156_2.png) [@Johannes\_Meiners](https://forum.dynamobim.com/u/Johannes_Meiners)\
**Post date:** [April 1, 2019, 12:19pm UTC](https://forum.dynamobim.com/t/list-control-combine-two-lists-with-lots-of-nulls-but-some-information/34224/4 "2019-04-01T12:19:07Z")

</div>

Try to replace “Null” with an empty string and then combine list:

 ![list-merge](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/6/e/6ea512bc6cefa2e60c760b26ce33645712deadc5.png)

---

<div class="post-metadata">

**Author:** ![jacob.small](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/jacob.small/32/161030_2.png) [@jacob.small](https://forum.dynamobim.com/u/jacob.small)\
**Post date:** [April 1, 2019, 1:55pm UTC](https://forum.dynamobim.com/t/list-control-combine-two-lists-with-lots-of-nulls-but-some-information/34224/5 "2019-04-01T13:55:24Z")

</div>

List.Create

List.Transpose

List.Clean

---

<div class="post-metadata">

**Author:** ![jonny.pye](https://avatars.discourse-cdn.com/v4/letter/j/3e96dc/32.png) [@jonny.pye](https://forum.dynamobim.com/u/jonny.pye)\
**Post date:** [April 1, 2019, 2:19pm UTC](https://forum.dynamobim.com/t/list-control-combine-two-lists-with-lots-of-nulls-but-some-information/34224/6 "2019-04-01T14:19:16Z")

</div>

Thanks Jacob, Could not get that to work. Jahannes suggestion seemed to get me on the track.

I used a list.replacenull with a space then ran the list combine. as shown.

Beautiful. Thanks for the help guys

 ![image](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/9/f/9f5eabfb89245ba8057f404650ad2d833afa4788.png)

---

<div class="post-metadata">

**Author:** ![Johannes\_Meiners](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/johannes_meiners/32/9156_2.png) [@Johannes\_Meiners](https://forum.dynamobim.com/u/Johannes_Meiners)\
**Post date:** [April 1, 2019, 2:32pm UTC](https://forum.dynamobim.com/t/list-control-combine-two-lists-with-lots-of-nulls-but-some-information/34224/7 "2019-04-01T14:32:29Z")

</div>

My suggestion is not that elegant, and keep an eye on empty spaces 😉

---

<div class="post-metadata">

**Author:** ![kennyb6](https://avatars.discourse-cdn.com/v4/letter/k/7ba0ec/32.png) [@kennyb6](https://forum.dynamobim.com/u/kennyb6)\
**Post date:** [April 2, 2019, 1:18am UTC](https://forum.dynamobim.com/t/list-control-combine-two-lists-with-lots-of-nulls-but-some-information/34224/8 "2019-04-02T01:18:20Z")

</div>

Here is an example of what @jacob.small said. If it did not work, it might be because you forgot to use False for preserveIndices input on List.Clean:

 ![combinewithoutnull](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/2/c/2c62133c21152e9ec6e8185a973e84fdcc5755ac.png)

Honestly, IMO it should be the best method, it avoids a lot of unnecessary steps that could cause problems.

Here is an if statement alternative as well:

 ![combinewithoutnull2](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/0/1/01c6040605ddb31e414347deeb320200055e6f9c.png)

---

<div class="post-metadata">

**Author:** ![jonny.pye](https://avatars.discourse-cdn.com/v4/letter/j/3e96dc/32.png) [@jonny.pye](https://forum.dynamobim.com/u/jonny.pye)\
**Post date:** [April 3, 2019, 8:27am UTC](https://forum.dynamobim.com/t/list-control-combine-two-lists-with-lots-of-nulls-but-some-information/34224/9 "2019-04-03T08:27:41Z")

</div>

That works great if you are creating a list with 0 nulls remaining. How ever I am looking for list structure similar to the excel sheet I posted above.

---

<div class="post-metadata">

**Author:** ![kennyb6](https://avatars.discourse-cdn.com/v4/letter/k/7ba0ec/32.png) [@kennyb6](https://forum.dynamobim.com/u/kennyb6)\
**Post date:** [April 3, 2019, 8:31am UTC](https://forum.dynamobim.com/t/list-control-combine-two-lists-with-lots-of-nulls-but-some-information/34224/10 "2019-04-03T08:31:15Z")

</div>

The if statement should still work then.  
 ![twolistnulls](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/b/c/bc187aa66effeb6bf945097d03bb0ee5e4a6049b.png)

Just trying to give an option that doesn’t rely on your inputs being strings and can handle other types.

---

<div class="post-metadata">

**Author:** ![jonny.pye](https://avatars.discourse-cdn.com/v4/letter/j/3e96dc/32.png) [@jonny.pye](https://forum.dynamobim.com/u/jonny.pye)\
**Post date:** [April 3, 2019, 8:37am UTC](https://forum.dynamobim.com/t/list-control-combine-two-lists-with-lots-of-nulls-but-some-information/34224/11 "2019-04-03T08:37:04Z")

</div>

I do apologise I thought both of those scripts did the same thing without trying. Very Grateful for the help that worked beautifully!

Out of interest do you know of some kind of code block cheat sheet for expressions, this solution has perfectly framed the elegance of using code blocks more often.

![image](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/a/b/ab69a3dc4d2f7c7db7cde6e10d7fa4cae1064a7e.png)

---

<div class="post-metadata">

**Author:** ![jonny.pye](https://avatars.discourse-cdn.com/v4/letter/j/3e96dc/32.png) [@jonny.pye](https://forum.dynamobim.com/u/jonny.pye)\
**Post date:** [April 3, 2019, 8:39am UTC](https://forum.dynamobim.com/t/list-control-combine-two-lists-with-lots-of-nulls-but-some-information/34224/12 "2019-04-03T08:39:06Z")

</div>

out of interest if i had 3 or 4 lists what would the code block look lilke?

---

<div class="post-metadata">

**Author:** ![kennyb6](https://avatars.discourse-cdn.com/v4/letter/k/7ba0ec/32.png) [@kennyb6](https://forum.dynamobim.com/u/kennyb6)\
**Post date:** [April 3, 2019, 8:42am UTC](https://forum.dynamobim.com/t/list-control-combine-two-lists-with-lots-of-nulls-but-some-information/34224/13 "2019-04-03T08:42:26Z")

</div>

Code blocks are written in design script, so you would need to look up information on that. I know there should be a few posts on where to find design script guides and information on the forum, just search “design script”.

Here is one pdf I use: [https://dynamobim.org/wp-content/links/DesignScriptGuide.pdf](https://dynamobim.org/wp-content/links/DesignScriptGuide.pdf)

and another intro guide: [http://designscript.io/DesignScript\_user\_manual\_0.1.pdf](http://designscript.io/DesignScript_user_manual_0.1.pdf)  
Somewhere in this one it describes in-line conditionals which is what I used.

I don’t have a cheat sheet for design script, though if there was one it would be incredibly handy.

As for if you had more lists, you would need to extend the if statement into an else if by adding more if statements in the false block (would be easier if instead of `==` you use `!=` or not equal to):

`w != null? w: (x != null?: x: (y != null? y: z));`  
Parenthesis might not be necessary but help to read.

---

<div class="post-metadata">

**Author:** ![jacob.small](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/jacob.small/32/161030_2.png) [@jacob.small](https://forum.dynamobim.com/u/jacob.small)\
**Post date:** [April 3, 2019, 8:59am UTC](https://forum.dynamobim.com/t/list-control-combine-two-lists-with-lots-of-nulls-but-some-information/34224/14 "2019-04-03T08:59:53Z")

</div>

Another good design script resource: [GitHub - Amoursol/dynamoDesignScript: DesignScript workflows for Dynamo](https://github.com/Amoursol/dynamoDesignScript)

---

<div class="post-metadata">

**Author:** ![Marcel\_Rijsmus](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/marcel_rijsmus/32/8539_2.png) [@Marcel\_Rijsmus](https://forum.dynamobim.com/u/Marcel_Rijsmus)\
**Post date:** [April 3, 2019, 10:40am UTC](https://forum.dynamobim.com/t/list-control-combine-two-lists-with-lots-of-nulls-but-some-information/34224/15 "2019-04-03T10:40:39Z")

</div>

more cheat sheets can be found here

> **[abhat222/Data-Science--Cheat-Sheet](https://github.com/abhat222/Data-Science--Cheat-Sheet)**
>
> Cheat Sheets. Contribute to abhat222/Data-Science--Cheat-Sheet development by creating an account on GitHub.
