ConvertDictOfListToListOfDict
Converts dictionary of lists to list of dictionaries.
python · Cofense Vision
Source
import demistomock as demisto # noqa: F401 from CommonServerPython import * # noqa: F401 def main(): try: args: dict = demisto.args() root = args.get("key", []) for i in root: if isinstance(root[i], int | str): root[i] = [root[i]] max_len = max([len(root[i]) for i in root]) for i in root: if len(root[i]) < max_len: root[i] = root[i] + list([" "] * (max_len - len(root[i]))) t = [dict(zip(root, i)) for i in zip(*root.values())] for arg in t: for key, val in arg.items(): if isinstance(val, str): arg[key] = val.strip() [remove_nulls_from_dictionary(i) for i in t] demisto.results(t) except Exception as e: demisto.error(traceback.format_exc()) return_error(f"Could not convert\n{e}") if __name__ in ("builtins", "__builtin__"): main()
README
Converts dictionary of lists to list of dictionaries.
Script Data
| Name | Description |
|---|---|
| Script Type | python3 |
| Tags | transformer |
| Cortex XSOAR Version | 6.2.0 |
Inputs
| Argument Name | Description |
|---|---|
| key | Object Key. |
Outputs
There are no outputs for this script.