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
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"])
for d in abc['orders']:
print (d["orderID"])
abc
has a key orders
which is a list.So you can iterate over the list.
The first think you need to do if you aren't done it already is to parse your file to a python dictionary. If you don't know how here is Link.
The next thing to do is to iterate through a nested dictionary which you can see how to do here: Link.
After doing those two steps you would be able to get all the keys and values you need in order to make further calculations.
Hope I helped you. I am new to writing answers not asking the questions. :)
Firebase Cloud Functions: PubSub, "res.on is not a function"
TypeError: Cannot read properties of undefined (reading 'createMessageComponentCollector')
I'm trying to partition DEBUG, INFO, and ERROR into seperate files due to a requirement
I'm constantly sending a camera's position matrix via UDP from Houdini and setting it in Cinema4dBoth are 3-D software programs
I have a text file I am designing for a mock store I named 'Bodn's Superstore'I designed a