InvertEveryTwoItems
This transformer will invert every two items in an array. Example: ["A", "B", "C", "D"] Result: ["B", "A", "D", "C"] If the total of items in the array is an odd number the last item will be removed Example: ["A", "B", "C", "D", "E"] Result: ["B", "A", "D", "C"] If the item is not an array the output will be same passed object.
python · Community Common Scripts
Source
import demistomock as demisto # noqa: F401 from CommonServerPython import * # noqa: F401 from itertools import chain value = [] value = demisto.args()["value"] list_out = list(chain.from_iterable(zip(value[1::2], value[::2]))) demisto.results(list_out)
README
This transformer will invert every two items in an array.
Example:
[“A”, “B”, “C”, “D”]
Result:
[“B”, “A”, “D”, “C”]
If the total of items in the array is an odd number the last item will be removed
Example:
[“A”, “B”, “C”, “D”, “E”]
Result:
[“B”, “A”, “D”, “C”]
If the item is not an array the output will be same passed object.
Script Data
| Name | Description |
|---|---|
| Script Type | python3 |
| Tags | transformer, list |
Inputs
| Argument Name | Description |
|---|---|
| value |
Outputs
There are no outputs for this script.