我有一个像这样的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','','','','']}
答案 0 :(得分:0)
简单地:
products['results']['images'] = [products['results']['images']]
答案 1 :(得分:0)
尝试使用列表理解:
products['results']['images'] = [products['results'][v] for v in products['results'] if v == 'images']