【发布时间】:2022-01-19 15:35:39
【问题描述】:
晚上好,我是python的初学者,我有一个代表客户历史的对象,代码如下:
history = [
{"email": "afrifran@gmail.com", "product": "pomme", "quantity_product": 12},
{"email": "afrifran@gmail.com", "product": "Viande", "quantity_product": 100},
{"email": "afrifran@gmail.com", "product": "pomme", "quantity_product": 18},
{"email": "afrifran@gmail.com", "product": "orange", "quantity_product": 2},
{"email": "afrifran@gmail.com", "product": "orange", "quantity_product": 3},
{"email": "popo@gmail.com", "product": "fraise", "quantity_product": 2},
{"email": "popo@gmail.com", "product": "fraise", "quantity_product": 8},
{"email": "popo@gmail.com", "product": "banane", "quantity_product": 12},
{"email": "popo@gmail.com", "product": "banane", "quantity_product": 3}]
我希望能够浏览对象,同时将与客户关联的每个产品的值串联起来,现在我已经冻结了几天。
我正在等待这样的输出:
obj = [{"email": "afrifran@gmail.com", "orange": 5, "pomme": 30, "Viande": 100}, {"email": "popo@gmail.com", "fraise": 10, "banane": 15}]
【问题讨论】:
-
你能提供想要的输出吗?
标签: python-3.x iteration concatenation