按城市分别算出的总额

👁️ 0 人浏览 💬 0 人评论 ❤️ 添加收藏

运行下面的 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)
提交你的答案
请登录后提交答案。
去登录
代码编辑器
Ctrl + Enter 运行
本次输入:
输出:

                        
👩‍🏫
AI
💬 题目评论

全部评论