I have the following code:
names = ['Mimi', 'Monique', 'Derick', 'Pierre', 'Sara', 'Marti', 'Isabel', 'Elicia', 'Dani', 'Bell']
surnames = ['Perez', 'Gomez', 'Sanchez', 'Iglesias', 'Casado', 'Mata', 'Li', 'Perez', 'Li', 'Gomez']
email = [names[i] + '_' + surnames[i] + '@email.com' for i in range(10)]
salary = [16000, 15000, 16000, 15000, 15000, 16000, 16000, 15000, 16000, 17000]
gender = ['F', 'F', 'M', 'M', 'F', 'M', 'F', 'F', 'M', 'F']
age = [31, 33, 30, 31, 34, 34, 31, 31, 32, 30]
list_of_keys = ['names', 'surnames', 'email', 'salary', 'gender', 'age']
list_of_lists = [names, surnames, email, salary, gender, age]
myDict = {}
for i in range(6):
myDict[list_of_keys[i]] = list_of_lists[i]
for i in myDict:
print(i,': ', myDict[i])
That has the following output
names : ['Mimi', 'Monique', 'Derick', 'Pierre', 'Sara', 'Marti', 'Isabel', 'Elicia', 'Dani', 'Bell']
surnames : ['Perez', 'Gomez', 'Sanchez', 'Iglesias', 'Casado', 'Mata', 'Li', 'Perez', 'Li', 'Gomez']
email : ['Mimi_Perez@email.com', 'Monique_Gomez@email.com', 'Derick_Sanchez@email.com', 'Pierre_Iglesias@email.com', 'Sara_Casado@email.com', 'Marti_Mata@email.com', 'Isabel_Li@email.com', 'Elicia_Perez@email.com', 'Dani_Li@email.com', 'Bell_Gomez@email.com']
salary : [16000, 15000, 16000, 15000, 15000, 16000, 16000, 15000, 16000, 17000]
gender : ['F', 'F', 'M', 'M', 'F', 'M', 'F', 'F', 'M', 'F']
age : [31, 33, 30, 31, 34, 34, 31, 31, 32, 30]
I would like to create the dictionary without having to manually write the variables 'list_of_keys' and 'list of lists'.
I also would like to use a list comprehension instead of a for loop, but I dont know how to do it when there is an '=' sign in the for loop.
Thank you