按城市分别算出的总额
运行下面的 Python 3 程序,填写结果。
orders = [{"city": "北京", "amount": 120},
{"city": "上海", "amount": 80},
{"city": "北京", "amount": 200},
{"city": "广州", "amount": 150}]
totals = {}
for o in orders:
c = o["city"]
totals[c] = totals.get(c, 0) + o["amount"]
print(totals)
全部评论