My ideia is to find every email in a sentence and replace it for a different random email (anonymization). But I can't get the result I want. Every email is replaced for the same one or I get an error (list index out of range)
input: email = "daniel@hotmail.com sent it to ana@gmail.com"
output I want email = "albert@hotmail.com sent it to john@gmail.com"
random_emails = ["albert", "john", "mary"]
def find_email(email: str):
result = email
i = 0
email_address = r"\S+@"
for text in email:
result = re.sub(email_address, random_emails[i] + "@", result)
i += 1
return result
print(find_email(email))