hi guys, I'm new to python and i can't seem to understand this one line of code right here:

distance, coordinates = min([(someFunction(state, coordinates), coordinates) for coordinates in coordinatesList])

coordinatesList contains a list of paired coordinates (x,y). someFunction returns an int. My question is why isn't distance and coordinates contain the same integer? i mean after the min() function, it should return an int, right? however, my print statements have coordinates as (someX, someY) and distance as some integer. How is this possible?

Min function does not return an int.
Min function gets a sequence and returns the lowest element of that sequence.
In that case this sequence is a list of (distance, coordinates) pairs.

If you have a list of distance and coordinates like:
It will return the (0,(1525,13)) element, because the first value of this element (zero) is the lowest among the other elements.

So we have a statement:
distance, coordinates = (0,(1525,13))

Distance will be 0, and coordinates will be (1525,13). It is called sequence unpacking.

Look up the docs:

Shows knowledge!
This question has already been answered. Start a new discussion instead.