Generation

generate functionWed, 18 Jan 2023

there is a dictionary: geo_data = {'Center': ['Moscow', 'Tula', 'Yaroslavl'], {'Northwest': ['Petersburg', 'Pskov', 'Murmansk'], 'Far East': ['Vladivostok', 'Sakhalin', 'Khabarovsk']} Write a function that will search the strings for the value of the dictionary, and if it exists, it will return the key of the dictionary. For example: geo_class('Pskov') Result: 'Northwest'

geo_data = {'Center': ['Moscow', 'Tula', 'Yaroslavl'], 'Northwest': ['Petersburg', 'Pskov', 'Murmansk'], 'Far East': ['Vladivostok', 'Sakhalin', 'Khabarovsk']} def geo_class(city): for region in geo_data: if city in geo_data[region]: return region geo_class('Pskov')

Questions about programming?Chat with your personal AI assistant