Hi everyone! I'm just learning how to write python, just started using Zapier and definitely see the opportunities for this being an amazing tool!
I am getting stuck on the following through.
I have the following data input:
countries = [
{"Country_Num": 1, "Country_Name": "United States"},
{"Country_Num": 2, "Country_Name": "United Kingdom"},
{"Country_Num": 3, "Country_Name": "Canada"},
{"Country_Num": 4, "Country_Name": "Germany"},
{"Country_Num": 5, "Country_Name": "France"},
{"Country_Num": 6, "Country_Name": "Australia"},
{"Country_Num": 7, "Country_Name": "Japan"},
{"Country_Num": 8, "Country_Name": "Brazil"},
{"Country_Num": 9, "Country_Name": "India"},
{"Country_Num": 10, "Country_Name": "South Africa"}
]
And I'm trying to turn this data into something useable in Zapier, so that I can add that data into a GoogleSheet.
Therefore, I'm using the Zapier step called "Run Python in Code by Zapier" and it allows me assign the input data above as "countries"
Now, I'm trying to use code to turn the data into two outputs that I can use using the following script:
# Accessing the input data which is provided as 'countries'
countries_data = input_data['countries']
# Initializing lists to hold country numbers and names
country_nums = []
country_names = []
# Iterating over each country in the input data
for country in countries_data:
# Appending the country number and name to their respective lists
country_nums.append(country["Country_Nums"])
country_names.append(country["Country_Names"])
# Preparing the output to include both lists
output = {'Country_Nums': country_nums, 'Country_Names': country_names}
return output
However, whenever I try to test the code, I get the following error:
Failed to create a run python in Code by Zapier
Your code had an error! Traceback (most recent call last): File "<string>", line 18, in the_function TypeError: string indices must be integers, not 'str'
Any help on this would be appreciated! Could this be because Zapier takes the data input as a string?