There is a list of email id and need to add key "email" to every elements in a list. Email list:
user = ["test@xyz.com","check@xyz.com"]
Here email key is to be added and output should be as. [{'email': 'test@xyz.com'}, {'email': 'check@xyz.com'}]
For this,
email_object = {}
email_list = []
user = ["test@xyz.com","check@xyz.com"]
for i in user:
email_object["email"] = i
email_list.append(email_object)
print(email_list)
Result:
[{'email': 'check@xyz.com'}, {'email': 'check@xyz.com'}]
Only last email address in a list is shown in a result. How to show output result as :
[{'email': 'test@xyz.com'}, {'email': 'check@xyz.com'}]