-5
abc = {
"orders": [
    {
        "orderID": 5,
        "cost": 10,
        "sell": 15
    },
    {
        "orderID": 6,
        "cost": 8,
        "sell": 12
    },
    {
        "orderID": 7,
        "cost": 15,
        "sell": 26           
        }
    ]
}

for key, value in abc.items():
print (value["orderID"])

I am trying to extract the orderID values, but cant seem to make this work. It should respond with 5,6,7

Scott Binkley
  • 153
  • 1
  • 2
  • 7

2 Answers2

2

right now you're looping over the abc dict. Instead, you want to loop over abc['orders']:

for order in abc['orders']:
    print (order["orderID"])
kmaork
  • 5,722
  • 2
  • 23
  • 40
0
for d in abc['orders']:
    print (d["orderID"])

abc has a key orders which is a list.So you can iterate over the list.

vks
  • 67,027
  • 10
  • 91
  • 124