Hi! I have an json (I will attach photo) and I want to extract from it a dictionary e.g. {name: [longitude, longitude]}
import json tags = {} coordonate = {} dictionar_coordonate = {} with open('json_generat.json') as f: data = json.load(f) def get_names(data): lista_nume = [] for el in data: lista_nume.append(el['name']) return lista_nume def get_coordonate(name): lista_coordonate = [] for el in data: if el['name'] == name: lista_coordonate.extend([el['latitude'],el['longitude']]) [u]-> the list is created[/u] break def get_latitude_longitude(): global dictionar_coordonate names = get_names(data) for name in names: dictionar_coordonate[name] = get_coordonate(name) -> [u]when I get here the output is {'name': None, ...}[/u] def afiseaza(): for name in dictionar_coordonate.keys(): print('#'*50) print('*'*10, 'Tags of', name, '*'*10) print('-'*50) print(', '.join(dictionar_coordonate[name])) print('-'*50) def start(): get_tags() afiseaza() get_latitude_longitude() start()
buran write Nov-01-2021, 06:39 PM:
Please, use proper tags when post code, traceback, output, etc. This time I have added tags for you.
See BBcode help for more info.
Please, use proper tags when post code, traceback, output, etc. This time I have added tags for you.
See BBcode help for more info.