python distance + for cycle question

hi. i have a list of objects in a tuple. i want to get distance from object X to the each objects in my list and then return the smallest of the distances.

i’m stuck in some weird for cycle :frowning: i know how to get the distance, hot to get the smallest value in a tuple but i can’t get this all to work together. :o


dist = 1000000 # big number
closest = None
for o in myTuple:
    newdist = # dist from x to o - You know how to do it!
    if newdist < dist:
        dist = newdist
        closest = o
# Here closest is the closest object - or None if no object is closer than big number

Or:


objects = (object1, object2, object3)
#assume that "object_x" is the object you can get the distances from
distances = sorted(objects, key=lambda x:object_x.getDistanceTo(x))
smallest = distances[0]

thanks this is working! i’ve been stuck in this for about 1 hour :smiley: