passing arguments to python script

Hi all

I am trying to pass the ansible hostnames as an array list to python script but could not figure out where the extra characters are coming from. I am passing with ansible_play_hosts_all variable.
In my host file there are 2 hoosts 1ld501 and 1ld994. but it is passing some unexpected character marked in red.

Playbook:

ansible_play_hosts_all is a list, which is what you say that you want, so all should be fine.

Unless your script does not really expect a list, which I think is what is happening.
If that is the case, either adopt your script to handle a list.
Or, turn the list into string, separated by spaces:

{{ ansible_play_hosts_all | join(" ") }}

The difference between a 'python list' ( [item, item2] ) and a 'shell
list' `item item2`, as @Dick Visser shows a simple join can translate
one to the other.

Thank you both for your kind help.
my python script expects a list. I am expecting something like below list
data= [[“1ld501”], [“1ld994”]]

This is working for me when I hardcoded inside python script. I am expecting similar list from ansible script.
with the above join command all the hostname concatenates to one string which I am not anticipating. Kindly help.

Regards

Hi again. Sorry if I am spamming.

I tried with below 2 option it is passing the argument as expected. I changed from double quotes to single quote now it is working.
{{ ansible_play_hosts_all | join(’ ') }}

{{ groups[‘all’] | join(’ ') }}

Thank you so much again