-1

How to turn this:

   dict = {"objects":[
                {
      "type": "node",
      "id": 46049199,
      "lat": 52.2925916,
      "lon": 4.9485062,
      "tags": {
      "traffic_calming": "table"
        }
    },
  {
      "type": "node",
      "id": 46053305,
      "lat": 52.2936706,
       "lon": 4.9469035,
       "tags": {
       "barrier": "gate"
      }
      },
      {
      "type": "node",
        "id": 46053351,
       "lat": 52.2934958,
       "lon": 4.9463902
        }

into this

      coordTD2 = {46049199: [52.2925916, 4.9485062], 46053305: [52.2936706, 4.9469035], 4 
        46053351: [52.2934958, 4.9463902]}
Dharman
  • 30,962
  • 25
  • 85
  • 135
  • 2
    What did you try so far? Where are you stuck? Please provide an [MCVE] to make helping you easier. Your task can be solved by iterating over your data and accessing the relevant data via its dict keys. Do you already know how lists and dicts are working? – albert Dec 01 '21 at 10:09

1 Answers1

2

Take every dictionary in the objects list and pick out the id, lat and lon as follows:

dic = {"objects":[
                {
      "type": "node",
      "id": 46049199,
      "lat": 52.2925916,
      "lon": 4.9485062,
      "tags": {
      "traffic_calming": "table"
        }
    },
  {
      "type": "node",
      "id": 46053305,
      "lat": 52.2936706,
       "lon": 4.9469035,
       "tags": {
       "barrier": "gate"
      }
      },
      {
      "type": "node",
        "id": 46053351,
       "lat": 52.2934958,
       "lon": 4.9463902
        },
    ]
}

newdic = {}
for d in dic['objects']:
   newdic[d['id']] = [d['lat'], d['lon']]

print(newdic)
match
  • 10,388
  • 3
  • 23
  • 41