Best answer

help with python code to split data

  • 13 July 2023
  • 5 replies
  • 255 views

Userlevel 1

Hey guys!

I really need your help since my programming skills aren't that great and Chat-GPT isn't a great help either.

I have the input data, which is basically just a bunch of emails divided by a comma. The goal is to write each email in a separate line, so I can access them in a later step in the Zap. 

The Split option in the formatter doesn’t work at all so I thought about programming it myself.

But I don't know how I have to write the code so python recognizes the email adresses. The adresses aren't static.

Can anybody help?

 

 

icon

Best answer by Troy Tessalone 13 July 2023, 18:42

View original

This post has been closed for comments. Please create a new post if you need help or have a question about this topic.

5 replies

Userlevel 7
Badge +14

Hi @ynnklo99 

Good question.

Can you clarify about the desired output you want for the email addresses by providing an example of the input vs output?

 

Some options to try…

Formatter > Text > Split

 

Formatter > Text > Replace

 

Formatter > Utilities > Line Items to Text

 

Userlevel 1

hey @Troy Tessalone thank you for the fast reply!

the input is: loremipsum@loremipsum.de,loremipsum@loremipsum.de

the output should be:

loremipsum@loremipsum.de

loremipsum@loremipsum.de

so I can access each adress later on.

The split action seems to be buggy but idk. It seems that it separated the two adresses, but later on they are again together with a comma.

The replace action I guess you replace the comma with a line break but idk how

The utlities action does not work at all.

 

Userlevel 7
Badge +14

@ynnklo99

Try this JavaScript Code, generated with the help of ChatGPT.

let Emails = inputData.Emails.split(',');

let emailObject = {};

Emails.forEach((email, index) => {
const propName = `email${index + 1}`;
emailObject[propName] = email;
});

output = [{Emails, emailObject}];

 

 

Userlevel 1

@Troy Tessalone wow, thank u so much!

 

Hey guys!

I really need  circular font your help since my programming skills aren't that great and Chat-GPT isn't a great help either.

I have the input data, which is basically just a bunch of emails divided by a comma. The goal is to write each email in a separate line, so I can access them in a later step in the Zap. 

The Split option in the formatter doesn’t work at all so I thought about programming it myself.

But I don't know how I have to write the code so python recognizes the email adresses. The adresses aren't static.

Can anybody help?

 

 

You can achieve this by using the split() method and specifying the comma (",") as the delimiter. Here's an example code snippet:

input_data = "email1@example.com, email2@example.com, email3@example.com" # Split the input data into a list of email addresses emails = input_data.split(", ") # Print each email address on a separate line for email in emails: print(email)

In this code, input_data represents your input string containing the email addresses. The split(", ") method is used to split the string into a list of email addresses, assuming that the email addresses are separated by a comma followed by a space.

You can replace the print(email) statement with your desired action, such as storing the email addresses in a variable, writing them to a file, or passing them to the subsequent steps in your Zap.