Answer the question
In order to leave comments, you need to log in
How to organize search by dictionary values?
We have a dictionary:
cities= {
'г. Москва':
['Москва', 'Moscow', 'Moscow > Moskva', 'г. Москва', 'г.Москва', 'Moskva (Moscow)'],
'г. Калиниград':
['Калининград', 'г.Калининград', 'Kaliningrad (Konigsberg)']
}
cv = cities.values()
ck = cities.keys()
adreses_alforder = [('Moscow > Moskva, ул. xxx, д. xxx' , 'Moscow > Moskva, ул. xxx, д. xxx'), ('Kaliningrad (Konigsberg), ' , 'Kaliningrad (Konigsberg), ')]
for i in adreses_alforder:
x = i[0].split(',') #взять первый элемент в каждом адресе и разделить адрес по запятым
print(x[0])
for i in adreses_alforder:
x = i[0].split(',') #беру первый элемент внутри i и разбиваю по запятой
xr = x[0] #здесь я беру первый элемент внутри переменной Х - город
if xr in cv():
print(x)
Answer the question
In order to leave comments, you need to log in
It?
cities= {
'г. Москва': [
'Москва', 'Moscow', 'Moscow > Moskva', 'г. Москва', 'г.Москва', 'Moskva (Moscow)'
],
'г. Калиниград': [
'Калининград', 'г.Калининград', 'Kaliningrad (Konigsberg)'
]
}
addresses_folder = [
('Moscow > Moskva, ул. xxx, д. xxx' , 'Moscow > Moskva, ул. xxx, д. xxx'),
('Kaliningrad (Konigsberg), ' , 'Kaliningrad (Konigsberg), ')
]
for address in addresses_folder:
address_city = address[0].split(',')[0]
for city, values in cities.items():
if address_city in values:
print(city)
г. Москва
г. Калиниград
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question