Skip to main content
 首页 » 编程设计

python之如何添加字典列表中的所有值

2025年05月04日12findumars

有没有一种简单的方法可以在 Python 中获取字典列表中所有水果的总价?

[{'name':'apple','price':10},{'name':'banana','price':5},{'name':'grapes','price':15}] 

请您参考如下方法:

尝试以下行:

sum(item['price'] for item in list)