编辑字典键名称

时间:2019-07-05 17:34:00

标签: python dictionary

我有一个返回字典的函数,我想将字典键名称(保留其值)编辑为["Merchant_1","Merchant_1_price","Merchant_1_link","Merchant_1_image","Merchant_1_stock"] 函数的输出相对相似,例如

a={'Merchant_3': 'Overstock', 'Merchant_3_price': '38.18', 'Merchant_3_link': 'https://www.overstock.com/Home-Garden/PUR-PPF951K3-Pitcher-Replacement-Filter-with-Lead-Reduction-Blue-3-Pack/24321917/product.html', 'Merchant_3_stock': 'Out of Stock', 'Merchant_3_image': '=IMAGE("https://ak1.ostkcdn.com/images/products/is/images/direct/e341bc23acc0843d3cb36f3cfd921d78fdb68ee5/PUR-PPF951K3-Pitcher-Replacement-Filter-with-Lead-Reduction%2C-Blue%2C-3-Pack.jpg",4,100,100)'}
b={'Merchant_6': '', 'Merchant_6_price': '', 'Merchant_6_link': '', 'Merchant_6_stock': '', 'Merchant_6_image': ''}

我想要的(小功能)是编辑Merchant_1的键并保留值。

预期输出:

a={'Merchant_1': 'Overstock', 'Merchant_1_price': '38.18', 'Merchant_1_link': 'https://www.overstock.com/Home-Garden/PUR-PPF951K3-Pitcher-Replacement-Filter-with-Lead-Reduction-Blue-3-Pack/24321917/product.html', 'Merchant_1_stock': 'Out of Stock', 'Merchant_1_image': '=IMAGE("https://ak1.ostkcdn.com/images/products/is/images/direct/e341bc23acc0843d3cb36f3cfd921d78fdb68ee5/PUR-PPF951K3-Pitcher-Replacement-Filter-with-Lead-Reduction%2C-Blue%2C-3-Pack.jpg",4,100,100)'}
b={'Merchant_1': '', 'Merchant_1_price': '', 'Merchant_1_link': '', 'Merchant_1_stock': '', 'Merchant_1_image': ''}

0 个答案:

没有答案