Same code in nodes (give accurate results) and Python behave differently with different geometry scaling preference settings

Hello all, I wrote a code for filtering some points using nodes it works perfectly and gives the same result with all the geometry scaling preferences small, medium, large and extra large and now I tried writing that in python i am not getting all the output points for some it is showing the values even tried with all the geometry scaling settings nothing is working.

Points sort.dyn (26.8 KB)
I cant able to upload the rvt file because of file size.
To recreate the issue open a new rvt prj place some random tees in MEP Fabrication Pipework Category. Thanks

Share a screenshot of the nodal version in action with the output you expect and paste the python code here as preformatted text (</>) so we can see what you’re working with. Also, always pin the node preview bubbles whenever you share a screenshot.

There will be some “minor” differences between the two languages based on what you’re doing - specifically with things like rounding and direct comparisons. The list logic may also vary between list levels and looping. We need to see what you’re doing in order to have an idea though.

Hi @Nick_Boyts the orange one i am refering as python version and the red one as nodal version and the codes have been attached in the dynamo file in the above texts.

PY-filtering the Tee Points code is this

# Load the Python Standard and DesignScript Libraries
import sys
import clr
from Autodesk.DesignScript.Geometry import *

import itertools

def ptscentroid(pts):
    for p in pts:
    return Point.ByCoordinates(sum(px)/len(pts),sum(py)/len(pts),sum(pz)/len(pts))

def teecenterpoints(pts):
    #group points by x
    iterator = itertools.groupby(pts, lambda pt : str(pt.X))
    for key, group in iterator:  
    #group points by y
    iterator = itertools.groupby(pts, lambda pt : str(pt.Y))
    for key, group in iterator:
    #group points by z
    iterator = itertools.groupby(pts, lambda pt : str(pt.Z))
    for key, group in iterator:

    #filtering the 2 points with the 2 points in the group 
    for gp in gps:
        if len(gp)==2:
            return ptscentroid(gp)
    del gps

# The inputs to this node will be stored as a list in the IN variables.
points = IN[0]

# Place your code below this line
for pts in points:

# Assign your output to the OUT variable.
OUT = o

Try rounding your x, y, and z values before grouping. Even for points that are otherwise identical, there can often be internal rounding issues at the nth decimal point that result in =/= point comparisons.