Python Snippet to Hash Email Addresses

I wanted to process some email address data today but hide the real email addresses. To do that I chose to run the SHA-256 hash over the email address data. Here’s the python snippet I used to convert the plain emails to the hashed versions (ignoring any emails with anything other than ASCII characters for simplicity):


import hashlib

plain_emails = ["user1@address1",
                "user2@address2"]

hashed_emails = [hashlib.sha256(bytes(mail.lower(), "ascii")).hexdigest()
                 for mail
                 in plain_emails]