如何删除数组中的第一个对象并将对象中的价格值乘以1000并在输出中添加一个总价格字段[暂停]

我有JSON输入,如下所示

Input =
    [{
    "place": "place",
    "product": "product",
    "price": "price"
    }, {

    "place": "chicago",
    "product": "Java",
    "price": "100"
    }, {

    "place": "newyork",
    "product": "python",
    "price": "200"
    }]

OUTPUT

应删除输入中的第一个对象,输入中的价格金额应乘以1000,并产生如下输出

[{

"place": "chicago",
"product": "Java",
"price": "100",
"Total price": "100000"
}, {

"place": "newyork",
"product": "python",
"price": "200"
"Totalprice": "200000"
}]

回答(2)

2 years ago

output = list(map(
    lambda x: dict(x, **{'price': str(int(x['price'])*1000)}
), input[1:]))

2 years ago

要通过索引从数组中删除元素,可以使用input.pop(index_nr) . 数组的第一个元素= 0.您的代码应如下所示:

input.pop(0)
for element in input:
    element["price"] = int(element["price"]) * 1000
print(input)