0

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!

1
  • I don't think this is json related as you don't seem to have any issue extracting the values from the json file. Commented Mar 15, 2016 at 13:21

1 Answer 1

3

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Worked like a charm! Perfect! Thanks a million!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.