1. Dig into an order
Write code Easy ✓ CompletedThe dict order is given. Create three variables:
city: the customer's citylast_name: the"name"of the last item inorder["items"](it should still work if more items are added)total_qty: the sum of the"qty"of all items
Then print city.
order = {
"id": 1042,
"customer": {"name": "Ben", "city": "Pune"},
"items": [
{"name": "pen", "qty": 4},
{"name": "notebook", "qty": 2},
{"name": "stapler", "qty": 1},
],
}
# your code here
order["items"] or use sum() with a generator expression.order = {
"id": 1042,
"customer": {"name": "Ben", "city": "Pune"},
"items": [
{"name": "pen", "qty": 4},
{"name": "notebook", "qty": 2},
{"name": "stapler", "qty": 1},
],
}
city = order["customer"]["city"]
last_name = order["items"][-1]["name"]
total_qty = sum(item["qty"] for item in order["items"])
print(city)