你和朋友要一起去露营,各列了一份装备 {东西: 几个}。写 pack_together(mine, yours),返回合起来的清单:两边都有的数量相加,先是你的东西,再是朋友多出来的。
pack_together({"tent": 1, "torch": 2}, {"torch": 1, "stove": 1})→{'tent': 1, 'torch': 3, 'stove': 1}pack_together({}, {})→{}def pack_together(mine, yours):
total = dict(mine)
for thing, n in yours.items():
# 在这里写:把朋友的这样东西加进 total(total 里没有就从 0 开始)
pass
return total
写好了先点「运行」试试示例,没问题再点「提交」。