dimanche 13 octobre 2019

How to extract right email from Dictionary based on names in a shuffled list

I want to obtain email addresses from a Dictionary related to people in a shuffled list.

I have a list of names that I shuffled and indexed them. I have also got email addresses of those names in a dictionary. Now I want to fetch the right email address based on the name in shuffled list and send an email to that person mentioning the index number they have.

The two codes are not talking to each other and there is a link I am missing as to how to fetch the right email. The desired solution is for example: For Beta, the code should fetch email of Beta from list and send email.

list_a = ["alpha","beta","romeo","nano","charlie"]

for idx, val in enumerate(list_a, start=0):
    print("index number for %s is %s" % (val, idx))

NameEmail = {
"alpha": "alpha@gmail.com",
"beta": "beta@gmail.com",
"romeo": "romeo@gmail.com",
"nano": "nano@gmail.com",
"charlie": "charlie@gmail.com",
}

for i in NameEmail:
    print(NameEmail.get(i))

index number for beta is 1
index number for romeo is 2
index number for nano is 3
index number for charlie is 4

alpha@gmail.com
beta@gmail.com
romeo@gmail.com
nano@gmail.com
charlie@gmail.com



Aucun commentaire:

Enregistrer un commentaire