How can I check and find the last character of the e-mail address from letters and numbers using Python?

93 Views Asked by At

I forgot the last 3 characters of the Gmail e-mail address of my Tiktok account. How to write and check individual letters and numbers consisting of A-Z, a-z and 0-9 letters and numbers in Python? i.e. how can I find it using A-Z, a-z and 0-9 letters and numbers in Python?

1

There are 1 best solutions below

0
Sash Sinha On

You can use itertools.product:

import itertools
import string

EMAIL_LOCAL_NAME_PREFIX = 'your_email_local_name_prefix'
EMAIL_DOMAIN_NAME = 'gmail.com'
CHARS = string.ascii_letters + string.digits # (A-Z, a-z, 0-9)

for p in itertools.product(CHARS, repeat=3):
    email_local_name_suffix = ''.join(p)
    email = f'{EMAIL_LOCAL_NAME_PREFIX}{email_local_name_suffix}@{EMAIL_DOMAIN_NAME}'
    print(email)

Output:

[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
...
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]

Note there are 238328 email addresses to check if you include uppercase letters... @Shai V. pointed out a good point that you might not need to check for both uppercase and lowercase letters. If that is the case you can use CHARS = string.ascii_lowercase_letters + string.digits # (a-z, 0-9). Subsequently, you will only need to check 46656 email addresses.