Solved
Stage 2 — finding the nearest
OP
How do I track the nearest waypoint while looping?
How do I track the nearest waypoint while looping?
Comments 4
Log in to join the discussion.
Log in Create accountKeep two variables before the loop: the best name and the best distance (start with None or infinity). In the loop, calculate the distance once, print it, and update the best if it's smaller.
float("inf")as the starting distance — neat trick.Right, min with key would call the function again. Good catch.
min()with a key could do it too, but the challenge wants one call per waypoint, so the loop is better.