0

I need to process a list of emails, cut them and make the output with counter of iterations

MailList = [[email protected], [email protected], [email protected]] # I have a list with emails # I need to process them and get next output: "User%number% is email1" I'm using something like: for c in MailList: print('user'+ ' is '+c[0:7]) # what I need to insert here to get desirable counter for my output? 

3 Answers 3

1

You need to split the emails with @ :

>>> MailList = ['[email protected]', '[email protected]', '[email protected]'] >>> for i in MailList : ... print ('user'+ ' is {}'.format(i.split('@')[0]) ) ... user is email1 user is email2 user is email3 
Sign up to request clarification or add additional context in comments.

Comments

0

If I understand correctly, you want this:

MailList = ["[email protected]", "[email protected]", "[email protected]"] for index, value in enumerate(MailList): print('user {} is {}'.format(index, value.split("@")[0])) 

See the docs for details on enumerate.

1 Comment

@AntonJakimenko I'm glad I could help you! If this answer (or another) solved your problem, it would be great if you could accept it.
0

using itertools.takewhile:

>>> import itertools >>> MailList = ['[email protected]', '[email protected]', '[email protected]'] >>> for x in MailList: ... print("user is {}".format("".join(itertools.takewhile(lambda x:x!='@',x)))) ... user is email1 user is email2 user is email3 

using index:

>>> for x in MailList: ... print("user is {}".format(x[:x.index('@')])) ... user is email1 user is email2 user is email3 

using find:

>>> for x in MailList: ... print("user is {}".format(x[:x.find('@')])) ... user is email1 user is email2 user is email3 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.