如何将散列键数组的 python 散列转换为数组?
How to convert python hash of array of hash key to array?
我有一个 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','','','','']}
简单地说:
products['results']['images'] = [products['results']['images']]
尝试使用列表理解:
products['results']['images'] = [products['results'][v] for v in products['results'] if v == 'images']
我有一个 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','','','','']}
简单地说:
products['results']['images'] = [products['results']['images']]
尝试使用列表理解:
products['results']['images'] = [products['results'][v] for v in products['results'] if v == 'images']