JavaScript
x
16
16
1
ItemList = [
2
{'name': 'item', 'item_code': '473', 'price': 0},
3
{'name': 'item', 'item_code': '510', 'price': 0},
4
{'name': 'item', 'item_code': '384', 'price': 0},
5
6
]
7
8
data_1 = '510'
9
data_2 = 200
10
11
def update_item(data_1, data_2):
12
for a in ItemList:
13
if a['item_code'] == data_1:
14
update_price = append(a['price'].data_2)
15
return True
16
I want to update the price by using the function update_item. It fails at update_price = append(a[‘price’].data_2)
Advertisement
Answer
You can assign the value to the dictionary, with:
JavaScript
1
5
1
def update_item(data_1, data_2):
2
for a in ItemList:
3
if a['item_code'] == data_1:
4
a['price'] = data_2
5
return