This is my dictionary.
data_item = {
"item": [
{
"ID": 141232,
"cost": 83500,
"quantity": 1
},
{
"ID": 45330,
"cost": 84600,
"quantity": 15
},
{
"ID": 31315,
"cost": 84800,
"quantity": 5
},
{
"ID": 50497,
"cost": 84800,
"quantity": 3
}
]
}
I am stuck with trying to access the "cost"...
I tried variations like
for k,v in data_item['item']:
if ['cost'] <= 84000:
price = ['cost']
print(f"Price is ${price}!")
and
for ['cost'] in data_item['item'].items:
if ['cost'] <= 84000:
price = ['cost']
print(f"Price is ${price}!")
and whole lot of variations in between ... I get errors like AttributeError: 'list' object has no attribute 'items' ValueError: too many values to unpack (expected 2)
I'm getting ready to just give up, but I though I would ask here first. How to access the value 'cost' so I can use it further in the code?
['cost']is a list, not accessing thecostelement of a dictionary.