# Produce a new list with elements that are only present in both list1 and list2

**URL:** <https://forum.dynamobim.com/t/produce-a-new-list-with-elements-that-are-only-present-in-both-list1-and-list2/94765>\
**Category:** Civil 3D\
**Created:** [October 20, 2023, 4:00pm UTC](https://forum.dynamobim.com/t/produce-a-new-list-with-elements-that-are-only-present-in-both-list1-and-list2/94765 "2023-10-20T16:00:22Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![jeff.wangD95HG](https://avatars.discourse-cdn.com/v4/letter/j/b5e925/32.png) [@jeff.wangD95HG](https://forum.dynamobim.com/u/jeff.wangD95HG)\
**Post date:** [October 20, 2023, 4:00pm UTC](https://forum.dynamobim.com/t/produce-a-new-list-with-elements-that-are-only-present-in-both-list1-and-list2/94765/1 "2023-10-20T16:00:22Z")

</div>

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

Hello I am new to dynamo here and I have coding background.  
I am trying to make a new list to select objects that is in layer “10” and is a line.  
base on the description from chatGPT I am assuming I need to check if the list 1 for list.contains elements of list 2 and output a boolean list to feed into list.filter by boolean.

there is 11 lines total and 3 in layer “10” and 1 polyline in layer “10”  
the output for list.filter have in as empty and out containing one polyline

---

<div class="post-metadata">

**Author:** ![Daan](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/daan/32/82246_2.png) [@Daan](https://forum.dynamobim.com/u/Daan)\
**Post date:** [October 20, 2023, 4:55pm UTC](https://forum.dynamobim.com/t/produce-a-new-list-with-elements-that-are-only-present-in-both-list1-and-list2/94765/2 "2023-10-20T16:55:52Z")

</div>

Hi @jeff.wangD95HG ,

Dont use ChatGPT for Dynamo.

Based on your title: use List.SetIntersection.

However, comparing like this is cumbersome and requires awkward logic and quite a bit of calculations, why not get all objects on layer 10 and only keep the lines using List.RemoveIfNot (or vice versa)

---

<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 20, 2023, 5:28pm UTC](https://forum.dynamobim.com/t/produce-a-new-list-with-elements-that-are-only-present-in-both-list1-and-list2/94765/3 "2023-10-20T17:28:49Z")

</div>

> [@Daan](#):
>
> Dont use ChatGPT for Dynamo.

1000 times this.

---

<div class="post-metadata">

**Author:** ![jeff.wangD95HG](https://avatars.discourse-cdn.com/v4/letter/j/b5e925/32.png) [@jeff.wangD95HG](https://forum.dynamobim.com/u/jeff.wangD95HG)\
**Post date:** [October 20, 2023, 6:14pm UTC](https://forum.dynamobim.com/t/produce-a-new-list-with-elements-that-are-only-present-in-both-list1-and-list2/94765/4 "2023-10-20T18:14:09Z")

</div>

![image](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/0/d/0dd84f5c2667515f6f62a3fd3c013fc9d8d1ccbc.png)  
setintersection gives an empty list.  
I am positive that there is 3 line object on layer “10”

well I am trying to create a generalized robust case to test out what dynamo can do and not working on workflow optimization yet.

---

<div class="post-metadata">

**Author:** ![patrick.ericson](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/patrick.ericson/32/121411_2.png) [@patrick.ericson](https://forum.dynamobim.com/u/patrick.ericson)\
**Post date:** [October 20, 2023, 6:35pm UTC](https://forum.dynamobim.com/t/produce-a-new-list-with-elements-that-are-only-present-in-both-list1-and-list2/94765/5 "2023-10-20T18:35:28Z")

</div>

If you want to see if they intersect, use the Geometry.Intersect instead but first convert them to dynamo geometry.

 ![image](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/8/d/8daf3788047a9838b9f6a272dca4c6058d0fc946.png)  
 ![image](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/e/7/e7426f85061ded8f340709aa59c3b90646137c2e.png)

---

<div class="post-metadata">

**Author:** ![jeff.wangD95HG](https://avatars.discourse-cdn.com/v4/letter/j/b5e925/32.png) [@jeff.wangD95HG](https://forum.dynamobim.com/u/jeff.wangD95HG)\
**Post date:** [October 20, 2023, 6:51pm UTC](https://forum.dynamobim.com/t/produce-a-new-list-with-elements-that-are-only-present-in-both-list1-and-list2/94765/6 "2023-10-20T18:51:00Z")

</div>

intersection in terms of lists means the common elements between the 2 list  
meaning a list of [1, 2, 3] and [0 , 5 , 6 , 3 , 7, 10 , 1] the intersection will be [1,3]

I am assuming  
object is a list of object IDs that fits the description  
so I am just intersecting two list of object IDs to create a list of object ID that is a line and in layer “10”

---

<div class="post-metadata">

**Author:** ![patrick.ericson](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/patrick.ericson/32/121411_2.png) [@patrick.ericson](https://forum.dynamobim.com/u/patrick.ericson)\
**Post date:** [October 20, 2023, 6:56pm UTC](https://forum.dynamobim.com/t/produce-a-new-list-with-elements-that-are-only-present-in-both-list1-and-list2/94765/7 "2023-10-20T18:56:58Z")

</div>

It’s a little bit different in Dynamo  
I don’t have a programmers background and started with Dynamo so I don’t think the same way, but when I start to learn about Python I find out that I understand more now after some practicing in Dynamo that I did before.

So what you want is objects of the type Line that is on layer 10?  
Like this? This script select the four lines on layer 10.

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

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

---

<div class="post-metadata">

**Author:** ![jeff.wangD95HG](https://avatars.discourse-cdn.com/v4/letter/j/b5e925/32.png) [@jeff.wangD95HG](https://forum.dynamobim.com/u/jeff.wangD95HG)\
**Post date:** [October 20, 2023, 7:11pm UTC](https://forum.dynamobim.com/t/produce-a-new-list-with-elements-that-are-only-present-in-both-list1-and-list2/94765/8 "2023-10-20T19:11:01Z")

</div>

ok thanks that is exactly what I am looking for.  
ChatGPT offered similar direction

---

<div class="post-metadata">

**Author:** ![patrick.ericson](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/patrick.ericson/32/121411_2.png) [@patrick.ericson](https://forum.dynamobim.com/u/patrick.ericson)\
**Post date:** [October 20, 2023, 7:12pm UTC](https://forum.dynamobim.com/t/produce-a-new-list-with-elements-that-are-only-present-in-both-list1-and-list2/94765/9 "2023-10-20T19:12:14Z")

</div>

Niice no worries  
Oki, but leave ChatGPT. This community is much more friendly and helpful 😉
