Answer the question
In order to leave comments, you need to log in
Geopy / how to find the closest point from a list?
there are two dictionaries:
income = {'': 'Error', 'Kaliningrad (Konigsberg), ': (54.710454, 20.512733), 'Krasnojarsk, Тельмана, 36': (56.05031, 92.967305), 'Moscow > Moskva, ': (55.755814, 37.617635), 'Moscow > Moskva, Багратионовский пр. д.7 кор.20Б': (55.743137, 37.504232)}
# в income могут быть строки!
etalon = {'115035, г. Москва, М-35, ул. Балчуг, 2': (55.747459, 37.625271), '308000, г. Белгород, пр-т Славы, 74': (50.598079, 36.585839), '241050, г. Брянск, ул. Горького, 34': (53.244984, 34.365707), '600000, г. Владимир, ул. Большая Московская, 29': (56.129745, 40.406446)}
x_values = income.values()
y_values = etalon.values()
from geopy.distance import geodesic
for x in x_values:
if type(x) == str:
None
else:
distance = 10000000 # выбираем какую-то от балды дистанцию побольше
for y in y_values():
try:
distance_new = geodesic(x, y, ellipsoid='WGS-84')
distance_new = geodesic(x_values, y_values, ellipsoid='WGS-84')
if distance_new < distance:
distance = distance_new
total = {income.keys(): etalon.keys()}
except:
print('Error')
Answer the question
In order to leave comments, you need to log in
dict.keys() returns Dictionary view objects (dict_keys), and this object is mutable and therefore cannot be a key in a dictionary.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question