To Get unique polycurves in a list of overlapping polycurve

Hello Fellow Dynamites!!!
I am trying to achieve the following polycurve list from a list of polycurves. and have tried a solution but facing problem in looping and some logic and inturn getting the result. Kindly, help me out i am attaching the codes which i have tried.


note: all the polycurves are overlapped

> # Load the Python Standard and DesignScript Libraries
> import sys
> import clr
> clr.AddReference('ProtoGeometry')
> from Autodesk.DesignScript.Geometry import *
> 
> from itertools import groupby
> 
> def flatten(l):
>     return [item for sublist in l for item in sublist]
> 
> # The inputs to this node will be stored as a list in the IN variables.
> pcrv = IN[0]
> 
> # Place your code below this line
> oc=[]
> boole=[]
> for pc in pcrv:
>     e=[]
>     for c in pc:
>         a=PolyCurve.Curves(c)
>         d=[]
>         for b in a:
>             c=str(Line.ByStartPointEndPoint(b.StartPoint,b.EndPoint))
>             d.append(c)
>         e.append(d)
>     bo=[]
>     for f in e:
>         boo=[]
>         for g in e:
>             bool=[]
>             for h in f:
>                 if h in g:
>                     bool.append(True)
>                     break
>                 else:
>                     bool.append(False)
>             if all(bool):
>                 boo.append(True)
>             else:
>                 boo.append(False)
>         bo.append(boo)
>     boole.append(bo)
>     for bl in bo:
>         i=sum(bl)
>         crvs=[]
>         for a,b in groupby(pc, lambda pc: i):
>             crvs.append(list(b))
>         crv=[]
>         for j in crvs:        
>             len=[k.Length for k in j]
>             maxlen=max(len)
>             mi=len.index(maxlen)
>             crv.append(j[mi])
>     oc.append(crv)
> 
> # Assign your output to the OUT variable.
> OUT = oc

If you want to make a logic, you must be able to explain it in words. It’s hard to understand your logic.

what I have tried in the code is:
1.The input Polycurve i am spitting into individual curves.
2.then with the individual curves of polycurve 1 I am checking, whether the polycurve 1’s curves are present in any of the polycurve’s curves present in the list.
3. if it is present make it is true.
4. now for each polycurve it should have only one complete intersection (which means all the curves of polycurve should be equal to all the other curves of one polycurve.
5. grouping by count and then getting the unique items list.

This logic i have tried but i need the same as shown in the above drawing, kindly let me know if you have any other logic

how can you define the polycurve#1?
you have to make consistant logic from the bottom to top.
I can’t find it from your image.


I am trying to say the below dynamo nodes logic

Polycurve 1 is for example it will go on iterating

@Vikram_Subbaiah and @jacob.small your thoughts on this

Geometry.AlmostEqualTo might be more effective here, but I don’t understand what you are attempting to do.

Geometry.IsAlmostEqualTo doesn’t give a correct answer.
Actually what i wanted to do is from the above diagram for eg.
if there are 2 red lines i want one redline with maximum length, if there are three green lines i wanted the greenline with the maximum length.