Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def summarize_params_diff(params_diff):
summary = ''
added_summary = [v.key for v in params_diff
if v.status() is DictValue.ADDED]
if added_summary:
summary += 'Parameters Added: %s\n' % ', '.join(added_summary)
removed_summary = [v.key for v in params_diff
if v.status() is DictValue.REMOVED]
if removed_summary:
summary += 'Parameters Removed: %s\n' % ', '.join(removed_summary)
modified_summary = [v.key for v in params_diff
if v.status() is DictValue.MODIFIED]
if modified_summary:
summary += 'Parameters Modified: %s\n' % ', '.join(modified_summary)
return summary
added_set = new_set - old_set
removed_set = old_set - new_set
common_set = old_set & new_set
changes = 0
output = []
for key in added_set:
changes += 1
output.append(DictValue(key, None, new_dict[key]))
for key in removed_set:
changes += 1
output.append(DictValue(key, old_dict[key], None))
for key in common_set:
output.append(DictValue(key, old_dict[key], new_dict[key]))
if str(old_dict[key]) != str(new_dict[key]):
changes += 1
output.sort(key=attrgetter("key"))
return [changes, output]
def summarize_params_diff(params_diff):
summary = ''
added_summary = [v.key for v in params_diff
if v.status() is DictValue.ADDED]
if added_summary:
summary += 'Parameters Added: %s\n' % ', '.join(added_summary)
removed_summary = [v.key for v in params_diff
if v.status() is DictValue.REMOVED]
if removed_summary:
summary += 'Parameters Removed: %s\n' % ', '.join(removed_summary)
modified_summary = [v.key for v in params_diff
if v.status() is DictValue.MODIFIED]
if modified_summary:
summary += 'Parameters Modified: %s\n' % ', '.join(modified_summary)
return summary
int: number of changed records
list: [DictValue]
"""
old_set = set(old_dict)
new_set = set(new_dict)
added_set = new_set - old_set
removed_set = old_set - new_set
common_set = old_set & new_set
changes = 0
output = []
for key in added_set:
changes += 1
output.append(DictValue(key, None, new_dict[key]))
for key in removed_set:
changes += 1
output.append(DictValue(key, old_dict[key], None))
for key in common_set:
output.append(DictValue(key, old_dict[key], new_dict[key]))
if str(old_dict[key]) != str(new_dict[key]):
changes += 1
output.sort(key=attrgetter("key"))
return [changes, output]
old_set = set(old_dict)
new_set = set(new_dict)
added_set = new_set - old_set
removed_set = old_set - new_set
common_set = old_set & new_set
changes = 0
output = []
for key in added_set:
changes += 1
output.append(DictValue(key, None, new_dict[key]))
for key in removed_set:
changes += 1
output.append(DictValue(key, old_dict[key], None))
for key in common_set:
output.append(DictValue(key, old_dict[key], new_dict[key]))
if str(old_dict[key]) != str(new_dict[key]):
changes += 1
output.sort(key=attrgetter("key"))
return [changes, output]