I'm looking for the way to convert string data that looks like the following:
"Kyiv, region A, 123\nKyiv, region B, 456\nKyiv, region C, 789\nPoltava, region D, 321\nPoltava, region E, 876\nPoltava, region F, 654"
to a 'dict' with two keys
{'city':'Kiev', 'population': 123}
I can convert substrings of the original string to lists of strings in this format:
[['Kyiv', 'region A', 123'], ['Kyiv', 'region B', '456'],] ...
but can't proceed further.
Could somebody help me parse this string?
This is the code I have so far:
dic_city = {}
cities = []
population = []
cities = [a.split(',') for a in s.split('\n')]
print(cities)