[英]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: 我有一个包含多个键的JSON文件:
{
"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. 我的计划是提取“ lat”和“ lon”值并将它们存储在python列表中,但要保持它们的对。
Therefore 因此
myList = [(54.600225,-5.920579),(0,0),(1,1)]..and so on myList = [(54.600225,-5.920579),(0,0),(1,1)] ..依此类推
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. 我正在查看list.append()函数,但是您只能传递一个对象,我认为这不是我想要的。
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. myList
是一个元组列表,您要添加一个元组。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.