简体   繁体   中英

Appending Multiple JSON values to same element in python list

I have this question, probably a simple enough answer but I can't find anything on this issue.

I have a JSON file containing multiple keys:

{
    "url": "https://farm8.staticflickr.com/7488/15664490410_3dc1a99796_b.jpg", 
    "location": {
        "lat": 54.600225, 
        "lon": -5.920579
    }, 
    "id": "15664490410_3dc1a99796_b.jpg", 
    "description": "[u'Belfast', u'night', u'Belfast City Centre', u'River Lagan', u'County Antrim', u'Northern Ireland', u'LovinBelfast', u'bridge', u'arches', u'sculpture', u'reflection', u'nighttime', u'Nuala with the Hula', u'Beacon of Hope', u'illumination', u'water', u'cityscape', u'Belfast Waterfront', u'Waterfront Hall', u'600D']"
},

My plan is to extract the 'lat' and 'lon' values and store them in a python list but maintaining their pair.

Therefore

myList = [(54.600225,-5.920579),(0,0),(1,1)]..and so on

I was looking at the list.append() function but you can only pass in a single object, which I dont think is what I want.

Hopefully someone can help!

Thanks!

Pass a tuple with the two values you want. The tuple is a single object.

myList.append((54.600225,-5.920579))

myList is a list of tuples and you're adding one tuple.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM