【发布时间】:2021-06-17 21:18:36
【问题描述】:
products = [
{"name": "samsung s6", "price": 3000},
{"name": "samsung s7", "price": 4000},
{"name": "samsung s8", "price": 5000},
{"name": "samsung s9", "price": 6000},
{"name": "samsung s10", "price": 7000}
]
for product in products:
for a, b in product.items():
print(b)
大家好。我想获取价格键的值并计算我拥有的所有物品的总价。获得它的最佳方法是什么?
【问题讨论】:
-
sum(d["price"] for d in products)
标签: python dictionary key