ddif1 may be like {'dictionaryitemadded': {"root['RNCName']": 'ALMARNC1',…
- User
ddif1 may be like {'dictionary_item_added': {"root['RNC_Name']": 'ALMA_RNC_1', "root['NodeB_Name']": '101184', "root['RNC_MO']": 'UtranCell=01184Z1'}} fix python code: delta = [] for fdn_dict in features_parameters: ddif1 = DeepDiff(baseline_part, fdn_dict, verbose_level=2,) print(ddif1) if ddif1['values_changed']["root['pwrOffset']"]['new_value'] == 'null': continue elif 'values_changed' in ddif1.keys(): delta.append(ddif1)
- Assistant
It seems like there are a few issues with the given code.
Firstly, the code does not include the necessary import statement for the
DeepDiffmodule. AssumingDeepDiffis from thedeepdiffpackage, you should add the following import statement at the beginning of your code:pythonfrom deepdiff import DeepDiffAdditionally, the
DeepDifffunction takes two arguments for comparison, but the code only provides one argument (baseline_part). You need to pass the second argument,fdn_dict, in theDeepDifffunction.Finally, the condition
ddif1['values_changed']["root['pwrOffset']"]['new_value'] == 'null'may lead to an error because the comparison is being performed with the string'null'. If you want to check if the new value isNone, you should use instead of comparing it to the string . - User
ddif1 may be like {'dictionary_item_added': {"root['RNC_Name']": 'AKTA_RNC_1', "root['NodeB_Name']": 'ERBS_52285_M4SCHOOLTW_2_KKT', "root['RNC_MO']": 'UtranCell=52285B1', "root['anrIafUtranCellConfig_sib11IafAnclEnabled']": 'FALSE', "root['anrIafUtranCellConfig_relationRemoveEnabled']": 'FALSE'}, 'values_changed': {"root['pwrOffset']": {'new_value': 'null', 'old_value': '10'}}}
- Assistant
Based on the updated information you provided, here's the revised code:
pythonfrom deepdiff import DeepDiff ddif1 = { 'dictionary_item_added': { "root['RNC_Name']": 'AKTA_RNC_1', "root['NodeB_Name']": 'ERBS_52285_M4SCHOOLTW_2_KKT', "root['RNC_MO']": 'UtranCell=52285B1', "root['anrIafUtranCellConfig_sib11IafAnclEnabled']": 'FALSE', "root['anrIafUtranCellConfig_relationRemoveEnabled']": 'FALSE' }, 'values_changed': { "root['pwrOffset']": {'new_value': 'null', 'old_value': '10'} } } delta = [] if 'values_changed' in ddif1: pwr_offset_change = ddif1['values_changed'].get("root['pwrOffset']") if pwr_offset_change is not None and pwr_offset_change['new_value'] is not None: delta.append(ddif1) print(delta)