I need to be able to pull the value of the key 'irr' from this json address in python:
IRR = conparameters['components'][i]['envelope'][j]['irr']
Even if 'irr' is any oher case, like IRR, Irr... etc.
Is that easy?
I need to be able to pull the value of the key 'irr' from this json address in python:
IRR = conparameters['components'][i]['envelope'][j]['irr']
Even if 'irr' is any oher case, like IRR, Irr... etc.
Is that easy?
There's nothing built-in that does it, you have to search for a matching key.
See Get the first item from an iterable that matches a condition for how to write a first()
function that finds the first element of an iterable that matches a condition. I'll use that in the solution below.
cur = conparameters['components'][i]['envelope'][j]
key = first(cur.keys(), lambda k: lower(k) == 'irr')
IRR = cur[key]