Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Updating values inside a python list

ItemList = [
    {'name': 'item', 'item_code': '473', 'price': 0},
    {'name': 'item', 'item_code': '510', 'price': 0},
    {'name': 'item', 'item_code': '384', 'price': 0},

]

data_1 = '510'
data_2 = 200

def update_item(data_1, data_2):
    for a in ItemList:
        if a['item_code'] == data_1:
            update_price = append(a['price'].data_2)
            return True

I want to update the price by using the function update_item. It fails at update_price = append(a[‘price’].data_2)

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

You can assign the value to the dictionary, with:

def update_item(data_1, data_2):
    for a in ItemList:
        if a['item_code'] == data_1:
            a['price'] = data_2
            return
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading