I'm trying to make a function that can track the pattern of an email. The function should take the firstname, lastname and domain and return the pattern for this domain.
So for example Joe Smith at Doodle Inc has the email adress: joe.smith@doodle.com.
The function should return {firstname}.{lastname}. But when the e-mail adress is j.smith@doodle.com it should return {firstname[0]}.{lastname} and so on.
I've already tried something by hardcoding all the different possibilites in a list and return the index of the correct item, but I'm looking for a way to do this smarter.
def find_pattern(fname, lname, email):
pp = [
fname + "." + lname,
fname + lname,
fname[0] + lname,
fname[0] + "." + lname,
lname,
lname + fname,
lname + fname[0],
lname + "." + fname[0],
lname + "." + fname[0],
fname + "_" + lname,
fname[0] + "_" + lname]
for x in range(len(pp)):
if email.split("@")[0] == pp[x]:
return x
Aucun commentaire:
Enregistrer un commentaire