如何将散列键数组的python散列转换为数组?

时间:2015-04-07 15:21:15

标签: python arrays dictionary hash

我有一个像这样的python字典

products = {'results': {'images': 'http://static13.jassets.com/p/Gini-26-Jony-Green-Casual-Shirt-9007-7386721-4-zoom.jpg', 'offers': {}, 'name': ['\n            Green Casual Shirt        '], 'features': {}, 'brand': ['\n            Gini & Jony        ']}}

我如何将图像密钥转换为数组?

现在的图像就像

{'images': 'http://static13.jassets.com/p/Gini-26-Jony-Green-Casual-Shirt-9007-7386721-4-zoom.jpg'}

但我希望图像是一个数组

{'images': ['http://static13.jassets.com/p/Gini-26-Jony-Green-Casual-Shirt-9007-7386721-4-zoom.jpg','','','','']}

2 个答案:

答案 0 :(得分:0)

简单地:

products['results']['images'] = [products['results']['images']]

示例:http://www.codeskulptor.org/#user39_Axyo9e7dCYT1Q7o.py

答案 1 :(得分:0)

尝试使用列表理解:

products['results']['images'] = [products['results'][v] for v in products['results'] if v == 'images']