Hi, I have data like these:

``````data_past    = [[62.0, 144.0, 3, 0]] where data_past=[[red_circle_x , red_circle_y , id_of_rectangle , status]]
data_current = [[60, 148, 0], [148, 127, 0]] where data_current=[[red_circle_x , red_circle_y , status]]
``````

And I want to compare each row of data_current to all data_past to get minimum distance, while status of data_past and data_current is 0, if 1 pass it
What should I put for it works so the program just calculate the distance when status

``````data_past and data_current is 0

for j in range(0,len(data_curr)):
for k in range(0,len(data_past)):
``````

Use list comprehension/generator with min-function.

I'm sorry I don't get it, could you explain it more detail? I'm just need help how I can run the nested for while the both data_past and data_current status is 0, the rest of program like distance minimum calculation is already made.. Just this problem that I can't get works..

Here is example of minimum function with iterable and function to calculate distance:

``````from math import hypot
from functools import partial

def distance(p1, p2):
return hypot(p2[1] - p1[1], p2[0] - p1[0])

points = [(81,3), (34, 32), (-4, 6)]

reference = (10,23)

print(min(points, key=partial(distance, reference)))
``````
commented: I didn't know hypot() ! +14
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.