JoinIfSingleElementOnly

Return the single element in case the array has only 1 element in it, otherwise return the whole array.

python · Filters And Transformers

Details

IDJoinIfSingleElementOnly
Languagepython
From Version5.0.0
Docker Imagedemisto/python3:3.12.13.10404775
Tagsentirelist transformer general

README

Returns the single element in a situation where an array has only 1 element in it, otherwise return the whole array.

Script Data


Name Description
Script Type python
Tags entirelist, transformer, general

Inputs


Argument Name Description
value The array to join if it has a single element.

Outputs


There are no outputs for this script.

import demistomock as demisto  # noqa: F401
from CommonServerPython import *  # noqa: F401


def return_first_element_if_single(value):
    res = value
    if isinstance(value, list) and len(value) == 1:
        res = value[0]
    return res


def main():  # pragma: no cover
    value = demisto.args()["value"]
    res = return_first_element_if_single(value)
    demisto.results(res)


if __name__ in ("__main__", "__builtin__", "builtins"):
    main()