I have a list with different email formatting, which I want to unify all in one. There are 2 types of email:
name.surname@dom
name.surname.extern@dom
My program allows the user to input emails, and to not have to enter "@dom"
all the time (it's always the same one), what I've done is allowing the user to write name.surname
or name.surname.e
and then the script replaces those usernames with @dom
or .extern@dom
The problem rises when I have all the mails in different formats stores in a list, and I want them to be filled to standards, so that if I have
["john.doe@dom", "john2.doe", "john3.doe.e","john4.doe.extern@dom"]
it all ends up looking like this
["john.doe@dom", "john2.doe@dom", "john3.doe.extern@dom","john4.doe.extern@dom"]
I have tried with list comprehensions, but all I got was three concatenations:
["%s.xtern@dom" % x for x in mails if x[-2:] == ".e"] +
["%s@dom" %x for x in mails if "@dom not in mails" and x[-2:] != ".e"] +
[x for x in mails if "@dom" in x]
I'm sure there's a better way that does not require me to do 3 list comprehensions and that does not require me to do
for i,v in enumerate(mails):
if "@dom" not in v:
mails[i] = "%s@dom" % v
etc.