List length is different than list length in Grasshoopper panel

I created a custom component using python, the code is very simple, it basically takes a bunch of multiple-segment curves and finds out if the first segment of curves intersect with berps, finally if the curve doesn’t intersect with the breps I add it to a list. Then I find the intersection points between the last segment of the curves in that list and a surface. I ran into a problem, if I print out the length of that list I get 242 (this is realistic) but the output in a grasshopper panel shows 1454 curves. Curves in the list are duplicated 4 times. Any ideas??

Update: I Attached the GH file (27.5 KB)

import Rhino as rc
import rhinoscriptsyntax as rs
import itertools

#Explode rays into line segments
explodedRays = rs.ExplodeCurves(rays)

#Get number of segments
numberOfSegments = int(len(explodedRays)/len(rays))

#Organize line segments into a list of lists
segments = []
for x in range(numberOfSegments):
    segment = explodedRays[x:][::numberOfSegments]
#Solve lines and obstructing surfaces intersection
intersectionPoints = []

for line in segments[0]:
    for brep in obstructingSrfs:
        newLine= rs.coercecurve(line) 
        allIntersectionPts = rc.Geometry.Intersect.Intersection.CurveBrep(newLine,brep, .0001)

#Put intersection points into a flattened list        
intersectionPts = list(itertools.chain.from_iterable(intersectionPoints))

# Get index of intersection points and apply indecies to line segments lists
intersectIndex = []
notIntersectIndex = []

for i, j in enumerate(intersectionPoints):
    if len(j) == 0:
newUnobstructedRays = [rays[i] for i in notIntersectIndex] 
obstructedRays = [rays[i] for i in intersectIndex] 

#newlist2 = [firstSegment[i] for i in b] 
#newlist3 = [secondSegment[i] for i in b]

newSegments= []
for x in range(numberOfSegments):
    newList = [segments[x][i] for i in notIntersectIndex] 

lastUnobstructedSegments = []    
for o in newSegments[-1]: 
    c = rs.coercecurve(o)

analysisIntersectionPoints = []
for l in lastUnobstructedSegments:
    for s in analysisSrfs:
        lines = rs.coercecurve(l) 
        newIntersectionPts = rc.Geometry.Intersect.Intersection.CurveBrep(lines,s, .0001)

analysisPts = list(itertools.chain.from_iterable(analysisIntersectionPoints))

cleanlist = []
[cleanlist.append(x) for x in analysisPts if x not in cleanlist]

#newUnobstructedRays1 =[ii for n,ii in enumerate(newUnobstructedRays) if ii not in newUnobstructedRays[:n]]
#print len(newUnobstructedRays1)

print len(newUnobstructedRays)

Hard to tell without a sample file, but have you checked if the inputs of your python component are set to List Access? Using the default Item Access would cause it to run multiple times.

The inputs are all set to “list access”.
I attached the file to the original post.

hmm… you’ve grafted the obstructingSrfs input which makes it a tree of single-itemed lists, and set it to list access, which means the component is running multiple times.

If you un-flatten the output you see that each iteration does match your printed list lengths.

@qythium thanks, that was it. I just realized that I didn’t reply to your answer, which was helpful!