cancel
Showing results for 
Search instead for 
Did you mean: 

Convert list of string to list of numbers

shefali
Deputy Chef I
Deputy Chef I

Is there a formula that can be used to convert list of String variables to a list of integers ? 

 

I/P is ["1","100","50", "4"] 
O/P [1,100,50,4]

1 ACCEPTED SOLUTION

Hi @shefali,
If you observe my screenshots:

1️⃣ In the 2nd and 3rd images,
I used Variable_name: List and Datatype: String. When applying the pluck("v") formula, it automatically converts to List_of_Numbers, so there's no need to explicitly set the data type as List.

2️⃣ I have a small curiosity: Why do we need to create two variables with Integer or Number data types to parse a number list?
Answer: There's no need to use two variables. As I suggested, when we apply the pluck("v") formula, it automatically takes care of converting to List_of_Numbers.

3️⃣ However, when using list functions, it still treats the variable as a list. Shouldn't it actually be recognized as a number instead?
Could you please share a screenshot? I didn’t fully understand your point here.

Looking forward to your insights! 😊

Thanks and Regards,
Shivakumar K A

View solution in original post

20 REPLIES 20

Prudvi
Executive Chef I
Executive Chef I

Hi @shefali,
You can do it using Execute Python Action:
input variable : num_list = list with string values
output variable : int_list = list with integer values
python_code.jpg


def main(input):
  string_list = input["num_list"]
  int_list = [int(x) for x in string_list]
  return {"int_list": int_list}

Regards,
Prudvi

Hi Prudvi,

I was wondering if this can be achieved using native formulas/functions, like List or String functions, instead of writing custom Python code?

shefali
Deputy Chef I
Deputy Chef I

Anyone has an idea if this can be done with help of existing functions/formulas in Workato?

Hi @shefali ,
Here is my answer to your question. What would be your next step after receiving the required response? 
Please let me know so that I can refine my answers.

String_list_1.PNGstring_list_response.PNG

Thanks and Regards,
Shivakumara K A