from list of tuples, get tuple closest to a given value
问题 Given a list of tuples containing coordinates, I want to find which coordinate is the closest to a coordinate I give in input: cooList = [(11.6702634, 72.313323), (31.67342698, 78.465323)] coordinate = (11.6702698, 78.113323) takenearest(myList, myNumber) ... (11.6702634, 72.313323) Please let me know... 回答1: For your data cooList = [(11.6702634, 72.313323), (31.67342698, 78.465323)] coordinate = (11.6702698, 78.113323) the shortest Pythonic answer is: nearest = min(cooList, key=lambda x: