Nov-30-2023, 03:17 PM
Slight problem, you can't do this:
Also, all values are strings, you will need to deal with that if you want to compare the numerical values.
I would collect the values you want as a list of tuples, then work on that. Never heard of nested_lookup!
None < -1You will get an error.
Also, all values are strings, you will need to deal with that if you want to compare the numerical values.
I would collect the values you want as a list of tuples, then work on that. Never heard of nested_lookup!
sample_dict = { "data": { "systemdata": [ { "system": "1", "tempData": { "temperature": "49C", "temperatureThreshold": "70C" } }, { "system": "2", "tempData": { "temperature": None, "temperatureThreshold": "-1C" }, } ], "detaildata": [ { "detail": "1", "tempData": { "temperature": "42C", "temperatureThreshold": "70C" }}, { "detail": "2", "tempData": { "temperature": "38C", "temperatureThreshold": "60C" }, } ] } } mydict = sample_dict['data'] mykeys = list(mydict.keys()) # ['systemdata', 'detaildata'] tups = [] for key in mykeys: mylist = mydict[key] print('The data is here in mylist[i][tempData]', mylist) print(f'mylist is {len(mylist)} long') for i in range(len(mylist)): tempdict = mylist[i]['tempData'] print('tempData is', tempdict) tup = (tempdict['temperature'], tempdict['temperatureThreshold']) tups.append(tup) for t in tups: print(t)The tups are:
Output:('49C', '70C')
(None, '-1C')
('42C', '70C')
('38C', '60C')