Python Forum

Full Version: print output none
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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()
Please take down the thumbnail. You shouldn't post addresses and phone numbers. It is also harder to test json code without a json file. Make a fake json file for testing and post that along with your code.
(Nov-01-2021, 08:10 PM)deanhystad Wrote: [ -> ]Please take down the thumbnail. You shouldn't post addresses and phone numbers. It is also harder to test json code without a json phone. Make a fake json file for testing and post that along with your code.
it's a fake one, it's random generated
i found the problem