有没有一种简单的方法可以在 Python 中获取字典列表中所有水果的总价?
[{'name':'apple','price':10},{'name':'banana','price':5},{'name':'grapes','price':15}]
请您参考如下方法:
尝试以下行:
sum(item['price'] for item in list)
有没有一种简单的方法可以在 Python 中获取字典列表中所有水果的总价?
[{'name':'apple','price':10},{'name':'banana','price':5},{'name':'grapes','price':15}]
请您参考如下方法:
尝试以下行:
sum(item['price'] for item in list)