What is the correct way to loop through the following json object?
test = [{
'start': 'ieo5',
'end': 'tiu9',
'chain': 10489
}, {
'start': 'qvc5',
'end': 'tiu9',
'chain': 45214
}, {
'start': 'ieo5',
'end': 'tiu9',
'chain': 69296
}]
I essentially want to loop through and print out whatever the value of start
is.
I've tried a bunch of options like the ones listed here but can't seem to get it to work.
This doesn't work:
for x in test
print x['start']
Your code logic works fine, just few things making it not work:
Since the tag is python-3.x, print
needs to be called.
Need colon after for line.
So the code would look like:
for x in test:
print(x['start'])
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With