# Sets question

**URL:** <https://discourse.mcneel.com/t/sets-question/98381>\
**Category:** Grasshopper\
**Tags:** python, math\
**Created:** [March 19, 2020, 2:14pm UTC](https://discourse.mcneel.com/t/sets-question/98381 "2020-03-19T14:14:42Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![anon39580149](https://avatars.discourse-cdn.com/v4/letter/a/977dab/32.png) [@anon39580149](https://discourse.mcneel.com/u/anon39580149)\
**Post date:** [March 19, 2020, 2:14pm UTC](https://discourse.mcneel.com/t/sets-question/98381/1 "2020-03-19T14:14:43Z")

</div>

Hello  
This problem about combine sets or tree branches which have similar numbers, @DavidRutten Already solved it years ago with c#  
And i think loop can do the same thing as the script but is there a method to do that with components or Python

 ![image](https://global.discourse-cdn.com/mcneel/uploads/default/original/3X/1/b/1b521f3d06b6c419bcdce3ccc7d68753fbfd5b5c.png)

 ![image](https://global.discourse-cdn.com/mcneel/uploads/default/original/3X/8/1/810d743ee650463df213fdb6f34ff24d4918ea6d.png)

[sets.gh](https://discourse.mcneel.com/uploads/short-url/a4Nrt1zdZMjmvyWY42qPOb2qYYH.gh) (6.4 KB)

---

<div class="post-metadata">

**Author:** ![AndersDeleuran](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/andersdeleuran/32/476683_2.png) [@AndersDeleuran](https://discourse.mcneel.com/u/AndersDeleuran)\
**Post date:** [March 19, 2020, 2:26pm UTC](https://discourse.mcneel.com/t/sets-question/98381/2 "2020-03-19T14:26:03Z")

</div>

I’m not quite sure I follow, but the Python [set class](https://docs.python.org/2.7/library/stdtypes.html#set) has methods such `union`, `intersection`, and `difference` (and more) that might help get you started.

---

<div class="post-metadata">

**Author:** ![anon39580149](https://avatars.discourse-cdn.com/v4/letter/a/977dab/32.png) [@anon39580149](https://discourse.mcneel.com/u/anon39580149)\
**Post date:** [March 19, 2020, 2:40pm UTC](https://discourse.mcneel.com/t/sets-question/98381/3 "2020-03-19T14:40:51Z")

</div>

Thanks, All these are available as components but how to resolve it this is the problem.

---

<div class="post-metadata">

**Author:** ![Jakinta](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/jakinta/32/485854_2.png) [@Jakinta](https://discourse.mcneel.com/u/Jakinta)\
**Post date:** [March 19, 2020, 2:58pm UTC](https://discourse.mcneel.com/t/sets-question/98381/4 "2020-03-19T14:58:18Z")

</div>

Just giving a try with geometrical approach…

 ![image](https://global.discourse-cdn.com/mcneel/uploads/default/original/3X/e/c/ecd1184adfb468505df7e8833aae17124976c9fc.png)

---

<div class="post-metadata">

**Author:** ![maje90](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/maje90/32/771922_2.png) [@maje90](https://discourse.mcneel.com/u/maje90)\
**Post date:** [March 19, 2020, 3:15pm UTC](https://discourse.mcneel.com/t/sets-question/98381/5 "2020-03-19T15:15:18Z")

</div>

In this specific case, @Jakinta, you have final set restults that doesn’t overlap.  
Region union is not good in this matter.  
Replace 11 with 3 and 3 with 11 on first panels and you’ll understand.

You can do something similar but with meshes, see here: [Sort intersected curves](https://discourse.mcneel.com/t/sort-intersected-curves/97676/8)

Also, I believe @anon39580149 is searching for a pure math (with sets) solution, without going geometric.

---

<div class="post-metadata">

**Author:** ![anon39580149](https://avatars.discourse-cdn.com/v4/letter/a/977dab/32.png) [@anon39580149](https://discourse.mcneel.com/u/anon39580149)\
**Post date:** [March 19, 2020, 3:27pm UTC](https://discourse.mcneel.com/t/sets-question/98381/6 "2020-03-19T15:27:02Z")

</div>

Hi @Jakinta, As @maje90 this will not work for case like this

 ![image](https://global.discourse-cdn.com/mcneel/uploads/default/original/3X/f/2/f292a5adc4b1d881c495edeb40bd90c85925b5f8.png)

This is a solution based on @maje90 idea in the thread mentionned

 ![image](https://global.discourse-cdn.com/mcneel/uploads/default/original/3X/8/7/8733cfbb179a3d055c9ea8c5beb26c9c49716fa6.png)

* * *

> [@maje90](#):
>
> pure math (with sets) solution,

Yes you are right , sometimes the solutions are very simple but i can’t find it and sometimes problems looks very simple but they are very complex.

---

<div class="post-metadata">

**Author:** ![djordje](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/djordje/32/747634_2.png) [@djordje](https://discourse.mcneel.com/u/djordje)\
**Post date:** [March 19, 2020, 3:28pm UTC](https://discourse.mcneel.com/t/sets-question/98381/7 "2020-03-19T15:28:44Z")

</div>

Hi @anon39580149,

![image](https://global.discourse-cdn.com/mcneel/uploads/default/original/3X/c/5/c51154322cef159b0f4edcd36073708842a9a901.png)  
Attached is a replica of David’s C# component in python.  
[sets py.gh](https://discourse.mcneel.com/uploads/short-url/khdeZxHpDP3Mb70bEDZ4VVRhVcp.gh) (8.0 KB)

---

<div class="post-metadata">

**Author:** ![Jakinta](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/jakinta/32/485854_2.png) [@Jakinta](https://discourse.mcneel.com/u/Jakinta)\
**Post date:** [March 19, 2020, 3:29pm UTC](https://discourse.mcneel.com/t/sets-question/98381/8 "2020-03-19T15:29:13Z")

</div>

That is correct. As soon as i posted it, realised it was wrong. 🤭

---

<div class="post-metadata">

**Author:** ![anon39580149](https://avatars.discourse-cdn.com/v4/letter/a/977dab/32.png) [@anon39580149](https://discourse.mcneel.com/u/anon39580149)\
**Post date:** [March 19, 2020, 3:31pm UTC](https://discourse.mcneel.com/t/sets-question/98381/9 "2020-03-19T15:31:46Z")

</div>

it’s a step for the right solution but as @maje90 said , the solution don’t work where branches have a single item, maybe will work by using set difference between the original tree and the result

---

<div class="post-metadata">

**Author:** ![maje90](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/maje90/32/771922_2.png) [@maje90](https://discourse.mcneel.com/u/maje90)\
**Post date:** [March 19, 2020, 3:34pm UTC](https://discourse.mcneel.com/t/sets-question/98381/10 "2020-03-19T15:34:14Z")

</div>

Ehm… indeed… I’ve just updated the other thread in the same way you described.

---

<div class="post-metadata">

**Author:** ![anon39580149](https://avatars.discourse-cdn.com/v4/letter/a/977dab/32.png) [@anon39580149](https://discourse.mcneel.com/u/anon39580149)\
**Post date:** [March 19, 2020, 3:35pm UTC](https://discourse.mcneel.com/t/sets-question/98381/11 "2020-03-19T15:35:34Z")

</div>

Thank you @djordje, it work fine; and it will help to solve many problems .  
I will convert it to a component if you accept

---

<div class="post-metadata">

**Author:** ![anon39580149](https://avatars.discourse-cdn.com/v4/letter/a/977dab/32.png) [@anon39580149](https://discourse.mcneel.com/u/anon39580149)\
**Post date:** [March 19, 2020, 3:39pm UTC](https://discourse.mcneel.com/t/sets-question/98381/12 "2020-03-19T15:39:32Z")

</div>

Solution of @djordje is the Python solution .  
And i still want find another solution with Math components if Grasshopper can do it .

---

<div class="post-metadata">

**Author:** ![anon39580149](https://avatars.discourse-cdn.com/v4/letter/a/977dab/32.png) [@anon39580149](https://discourse.mcneel.com/u/anon39580149)\
**Post date:** [March 19, 2020, 4:04pm UTC](https://discourse.mcneel.com/t/sets-question/98381/13 "2020-03-19T16:04:00Z")

</div>

This solution based on ideas of @maje90 and @Jakinta

[sets.gh](https://discourse.mcneel.com/uploads/short-url/qOibBKp8dYlsVxAz8ohhpFCr0x0.gh) (14.0 KB)

 ![image](https://global.discourse-cdn.com/mcneel/uploads/default/original/3X/f/7/f7c588ea05bcaea9407d61da7d8802c4790d883b.png)

---

<div class="post-metadata">

**Author:** ![anon39580149](https://avatars.discourse-cdn.com/v4/letter/a/977dab/32.png) [@anon39580149](https://discourse.mcneel.com/u/anon39580149)\
**Post date:** [March 19, 2020, 4:28pm UTC](https://discourse.mcneel.com/t/sets-question/98381/14 "2020-03-19T16:28:50Z")

</div>

Ghpython component , i called it **Sets intersection** , i don’t know if it is the right term.

Credit to @djordje & @DavidRutten

[Sets Intersection.ghpy](https://discourse.mcneel.com/uploads/short-url/hCYYviBsgCO4XYzFyq0fjwUjXmz.ghpy) (24 KB)

 ![image](https://global.discourse-cdn.com/mcneel/uploads/default/original/3X/b/f/bf218047163b50df6cb2d05e663d203ee6a4169a.png)
