Reputation: 442
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?
Upvotes: 0
Views: 64
Reputation: 19733
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
Upvotes: 0
Reputation: 11060
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
.
Upvotes: 0
Reputation: 107287
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
Upvotes: 1