# Pull highest value from two lists to create new list

**URL:** <https://forum.dynamobim.com/t/pull-highest-value-from-two-lists-to-create-new-list/94476>\
**Category:** Revit\
**Created:** [October 11, 2023, 4:43pm UTC](https://forum.dynamobim.com/t/pull-highest-value-from-two-lists-to-create-new-list/94476 "2023-10-11T16:43:40Z")\
**Posts on this page:** 19\
**Page:** 1

<div class="post-metadata">

**Author:** ![ahuls](https://avatars.discourse-cdn.com/v4/letter/a/fbc32d/32.png) [@ahuls](https://forum.dynamobim.com/u/ahuls)\
**Post date:** [October 11, 2023, 4:43pm UTC](https://forum.dynamobim.com/t/pull-highest-value-from-two-lists-to-create-new-list/94476/1 "2023-10-11T16:43:40Z")

</div>

Hello All!

Absolute Dynamo nube here, but I’m trying to bend my brain around this. I’m sure it’s easier than I’m making it, but I don’t know what I don’t know. ☹

I need to compare two lists (“Rough Width” and “Width”) and create a new list of values based on highest value from each, then use that new list to govern the “Width” of my newly placed family instance. The lists will always have the same number of responses, so my thought was to have a Python script compare line by line and return the greater value but I think I’m running into an issue with some of the values since they have an extensive decimal extension. Maybe? I dunno, I’m guessing…

The ultimate goal is to place a family instance in Revit at each door/window opening that matches the width of the overall opening. Since some families use a governing parameter of “Width” and some use “Rough Width”, I need to accommodate for both. My script works great for one or the other but not both. The value field for “Rough Width” is empty if it is not governing, which means I need the script to default to the “Width” value.

Here is a screen shot of what I currently have and the error I’m getting for my Python script:

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

Any help would be greatly appreciated!

---

<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:** [October 11, 2023, 4:55pm UTC](https://forum.dynamobim.com/t/pull-highest-value-from-two-lists-to-create-new-list/94476/2 "2023-10-11T16:55:05Z")

</div>

Join the two lists into one with a List.Create node. Then use a List.Transpose node to get value pairs, and finally use a List.MaximumItem with level set to @L2 in order to get the larger of the two values.

---

<div class="post-metadata">

**Author:** ![Nick\_Boyts](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/nick_boyts/32/76313_2.png) [@Nick\_Boyts](https://forum.dynamobim.com/u/Nick_Boyts)\
**Post date:** [October 11, 2023, 5:29pm UTC](https://forum.dynamobim.com/t/pull-highest-value-from-two-lists-to-create-new-list/94476/3 "2023-10-11T17:29:29Z")

</div>

You can also use a simple conditional statement:  
`a > b ? a : b;`

---

<div class="post-metadata">

**Author:** ![ahuls](https://avatars.discourse-cdn.com/v4/letter/a/fbc32d/32.png) [@ahuls](https://forum.dynamobim.com/u/ahuls)\
**Post date:** [October 11, 2023, 5:30pm UTC](https://forum.dynamobim.com/t/pull-highest-value-from-two-lists-to-create-new-list/94476/4 "2023-10-11T17:30:30Z")

</div>

@Nick_Boyts , thank you! Um… where would I put the conditional statement?

---

<div class="post-metadata">

**Author:** ![Nick\_Boyts](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/nick_boyts/32/76313_2.png) [@Nick\_Boyts](https://forum.dynamobim.com/u/Nick_Boyts)\
**Post date:** [October 11, 2023, 5:32pm UTC](https://forum.dynamobim.com/t/pull-highest-value-from-two-lists-to-create-new-list/94476/5 "2023-10-11T17:32:27Z")

</div>

You would provide the Rough Width and Width as the variables `a` and `b` and the result would be the higher value. You would then pass on that value to the instance as the new Width.

---

<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:** [October 11, 2023, 5:32pm UTC](https://forum.dynamobim.com/t/pull-highest-value-from-two-lists-to-create-new-list/94476/6 "2023-10-11T17:32:41Z")

</div>

A null value might cause some issues with this, but worth a shot as it would be one node.

---

<div class="post-metadata">

**Author:** ![Nick\_Boyts](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/nick_boyts/32/76313_2.png) [@Nick\_Boyts](https://forum.dynamobim.com/u/Nick_Boyts)\
**Post date:** [October 11, 2023, 5:33pm UTC](https://forum.dynamobim.com/t/pull-highest-value-from-two-lists-to-create-new-list/94476/7 "2023-10-11T17:33:32Z")

</div>

True, I missed that part. You would either need to ensure you have no nulls (replace with 0) or include another condition for null or empty values.

---

<div class="post-metadata">

**Author:** ![ahuls](https://avatars.discourse-cdn.com/v4/letter/a/fbc32d/32.png) [@ahuls](https://forum.dynamobim.com/u/ahuls)\
**Post date:** [October 11, 2023, 5:33pm UTC](https://forum.dynamobim.com/t/pull-highest-value-from-two-lists-to-create-new-list/94476/8 "2023-10-11T17:33:33Z")

</div>

I fear the Null is causing issues:

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

---

<div class="post-metadata">

**Author:** ![ahuls](https://avatars.discourse-cdn.com/v4/letter/a/fbc32d/32.png) [@ahuls](https://forum.dynamobim.com/u/ahuls)\
**Post date:** [October 11, 2023, 5:34pm UTC](https://forum.dynamobim.com/t/pull-highest-value-from-two-lists-to-create-new-list/94476/9 "2023-10-11T17:34:03Z")

</div>

I’ll give it a whirl…

---

<div class="post-metadata">

**Author:** ![christian.stan](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/christian.stan/32/166296_2.png) [@christian.stan](https://forum.dynamobim.com/u/christian.stan)\
**Post date:** [October 11, 2023, 5:38pm UTC](https://forum.dynamobim.com/t/pull-highest-value-from-two-lists-to-create-new-list/94476/10 "2023-10-11T17:38:46Z")

</div>

hello

 ![image](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/4/9/4944ae2c5442141a9eba7e68c4f6ad8f2763c007.png)  
cordially  
christian.stan

---

<div class="post-metadata">

**Author:** ![ahuls](https://avatars.discourse-cdn.com/v4/letter/a/fbc32d/32.png) [@ahuls](https://forum.dynamobim.com/u/ahuls)\
**Post date:** [October 11, 2023, 5:42pm UTC](https://forum.dynamobim.com/t/pull-highest-value-from-two-lists-to-create-new-list/94476/11 "2023-10-11T17:42:28Z")

</div>

This is closer! However, I need for it to do a line by line comparison of which value is greater.

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

For what it’s worth, I’ve tried approaching this with a couple of different angles, but the list comparison seemed to be the cleanest.

---

<div class="post-metadata">

**Author:** ![Nick\_Boyts](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/nick_boyts/32/76313_2.png) [@Nick\_Boyts](https://forum.dynamobim.com/u/Nick_Boyts)\
**Post date:** [October 11, 2023, 5:45pm UTC](https://forum.dynamobim.com/t/pull-highest-value-from-two-lists-to-create-new-list/94476/12 "2023-10-11T17:45:31Z")

</div>

You changed the list structure with `AllIndicesOf` (it returns a list).

You can use something like `ReplaceByCondition` (which would require you to address both null and empty conditions separately) or use another nested conditional statement for values equal to `null` or empty (`""`).

---

<div class="post-metadata">

**Author:** ![christian.stan](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/christian.stan/32/166296_2.png) [@christian.stan](https://forum.dynamobim.com/u/christian.stan)\
**Post date:** [October 11, 2023, 5:48pm UTC](https://forum.dynamobim.com/t/pull-highest-value-from-two-lists-to-create-new-list/94476/13 "2023-10-11T17:48:45Z")

</div>

![image](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/3/5/359ee9cd1078b70a3415ab34471e7d897ce2fdae.png)  
cordially  
christian.stan

---

<div class="post-metadata">

**Author:** ![ahuls](https://avatars.discourse-cdn.com/v4/letter/a/fbc32d/32.png) [@ahuls](https://forum.dynamobim.com/u/ahuls)\
**Post date:** [October 11, 2023, 5:55pm UTC](https://forum.dynamobim.com/t/pull-highest-value-from-two-lists-to-create-new-list/94476/14 "2023-10-11T17:55:02Z")

</div>

So, I tried flattening the list and that seemed to work:

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

Unless I’m missing something?

---

<div class="post-metadata">

**Author:** ![ahuls](https://avatars.discourse-cdn.com/v4/letter/a/fbc32d/32.png) [@ahuls](https://forum.dynamobim.com/u/ahuls)\
**Post date:** [October 11, 2023, 5:58pm UTC](https://forum.dynamobim.com/t/pull-highest-value-from-two-lists-to-create-new-list/94476/15 "2023-10-11T17:58:47Z")

</div>

Thank you! I tried it and it still seemed to return only the highest values, not the highest value per line, but I will store the information that I can specify the level like that.

---

<div class="post-metadata">

**Author:** ![Nick\_Boyts](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/nick_boyts/32/76313_2.png) [@Nick\_Boyts](https://forum.dynamobim.com/u/Nick_Boyts)\
**Post date:** [October 11, 2023, 5:58pm UTC](https://forum.dynamobim.com/t/pull-highest-value-from-two-lists-to-create-new-list/94476/16 "2023-10-11T17:58:50Z")

</div>

That does work but you’re better off just not adding the extra level to begin with. Instead, convert your non-numeric values to 0 with a conditional statement.

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

---

<div class="post-metadata">

**Author:** ![ahuls](https://avatars.discourse-cdn.com/v4/letter/a/fbc32d/32.png) [@ahuls](https://forum.dynamobim.com/u/ahuls)\
**Post date:** [October 11, 2023, 6:01pm UTC](https://forum.dynamobim.com/t/pull-highest-value-from-two-lists-to-create-new-list/94476/17 "2023-10-11T18:01:44Z")

</div>

That’s the bit of code that I kept circling around but didn’t know enough to put it together on my own. Thank you!!

---

<div class="post-metadata">

**Author:** ![krunalthakor645](https://avatars.discourse-cdn.com/v4/letter/k/919ad9/32.png) [@krunalthakor645](https://forum.dynamobim.com/u/krunalthakor645)\
**Post date:** [February 1, 2025, 6:54am UTC](https://forum.dynamobim.com/t/pull-highest-value-from-two-lists-to-create-new-list/94476/18 "2025-02-01T06:54:12Z")

</div>

Hi @Nick_Boyts, @jacob.small and All  
I want to filter two highest value from every sub-list and I have apply the following logic.

But, sometimes it works and sometimes not. do you have any Idea why I get same index in the following script.

 ![image](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/4/c/4c82071485c6b287c8776ccd095aee4824a4fc0c.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:** [February 1, 2025, 11:10am UTC](https://forum.dynamobim.com/t/pull-highest-value-from-two-lists-to-create-new-list/94476/19 "2025-02-01T11:10:27Z")

</div>

List.MaximumItem node with the list input set to @L2 to start. This will get the largest area from each sublist.

List.SetDifference with the list of sublists for list A and the individual maximum values as list B. Set list A to @L2 and list B to @L1.

If you want to remove the surface, not the area from the list use a List.MaximumItemByKey node set to @L2 for the list input and with a key input of the Surface.Area node with nothing wired into it. That becomes the list B input in the List.SetDifference node.

If you can’t make that work please start a new topic so we don’t get deviations in conflicting solutions. Be sure to include a dyn and relevant source data.
