I am trying to create a nested dictionary using multiple lists,
My code is:
proj={}
project=["Project 1","Project 2","Project 3", "Prjoect 4", "Project 5"]
scraping_valuable_data = [5898,3000,3245,9066,6002]
data_annotation = [70200,52900,6000,82813,68400]
project_manager = [80000,90000,70000,70000,90000]
AI_R_and_D = [50000,50000,50000,50000,50000]
infrastructure_costs = [3600,2000,3600,3600,3600]
integration_costs = [2500,3500,2500,2500,2500]
maintenance_costs = [50000,50000,50000,50000,60000]
num_R_and_D = [2,3,2,3,2]
time_scale_project = [12,6,18,12,18]
project_impact = [0.9,0.5,0.4,0.8,0.1]
for i, project in enumerate(project):
proj[project] = {
'scraping_valuable_data': scraping_valuable_data[i],
'data_annotation':data_annotation[i],
'project_manager':project_manager[i],
'AI_R_and_D':AI_R_and_D[i],
'infrastructure_costs':infrastructure_costs[i],
'integration_costs':integration_costs[i],
'maintenance_costs':maintenance_costs[i],
'num_R_and_D':num_R_and_D[i],
'time_scale_project':time_scale_project[i],
'project_impact':project_impact[i]}
print(proj)
My current output is the following:
{'Project 1': {'scraping_valuable_data': 5898, 'data_annotation': 70200, 'project_manager': 80000, 'AI_R_and_D': 50000, 'infrastructure_costs': 3600, 'integration_costs': 2500, 'maintenance_costs': 50000, 'num_R_and_D': 2, 'time_scale_project': 12, 'project_impact': 0.9}}
{'Project 1': {'scraping_valuable_data': 5898, 'data_annotation': 70200, 'project_manager': 80000, 'AI_R_and_D': 50000, 'infrastructure_costs': 3600, 'integration_costs': 2500, 'maintenance_costs': 50000, 'num_R_and_D': 2, 'time_scale_project': 12, 'project_impact': 0.9}, 'Project 2': {'scraping_valuable_data': 3000, 'data_annotation': 52900, 'project_manager': 90000, 'AI_R_and_D': 50000, 'infrastructure_costs': 2000, 'integration_costs': 3500, 'maintenance_costs': 50000, 'num_R_and_D': 3, 'time_scale_project': 6, 'project_impact': 0.5}}
{'Project 1': {'scraping_valuable_data': 5898, 'data_annotation': 70200, 'project_manager': 80000, 'AI_R_and_D': 50000, 'infrastructure_costs': 3600, 'integration_costs': 2500, 'maintenance_costs': 50000, 'num_R_and_D': 2, 'time_scale_project': 12, 'project_impact': 0.9}, 'Project 2': {'scraping_valuable_data': 3000, 'data_annotation': 52900, 'project_manager': 90000, 'AI_R_and_D': 50000, 'infrastructure_costs': 2000, 'integration_costs': 3500, 'maintenance_costs': 50000, 'num_R_and_D': 3, 'time_scale_project': 6, 'project_impact': 0.5}, 'Project 3': {'scraping_valuable_data': 3245, 'data_annotation': 6000, 'project_manager': 70000, 'AI_R_and_D': 50000, 'infrastructure_costs': 3600, 'integration_costs': 2500, 'maintenance_costs': 50000, 'num_R_and_D': 2, 'time_scale_project': 18, 'project_impact': 0.4}}
{'Project 1': {'scraping_valuable_data': 5898, 'data_annotation': 70200, 'project_manager': 80000, 'AI_R_and_D': 50000, 'infrastructure_costs': 3600, 'integration_costs': 2500, 'maintenance_costs': 50000, 'num_R_and_D': 2, 'time_scale_project': 12, 'project_impact': 0.9}, 'Project 2': {'scraping_valuable_data': 3000, 'data_annotation': 52900, 'project_manager': 90000, 'AI_R_and_D': 50000, 'infrastructure_costs': 2000, 'integration_costs': 3500, 'maintenance_costs': 50000, 'num_R_and_D': 3, 'time_scale_project': 6, 'project_impact': 0.5}, 'Project 3': {'scraping_valuable_data': 3245, 'data_annotation': 6000, 'project_manager': 70000, 'AI_R_and_D': 50000, 'infrastructure_costs': 3600, 'integration_costs': 2500, 'maintenance_costs': 50000, 'num_R_and_D': 2, 'time_scale_project': 18, 'project_impact': 0.4}, 'Prjoect 4': {'scraping_valuable_data': 9066, 'data_annotation': 82813, 'project_manager': 70000, 'AI_R_and_D': 50000, 'infrastructure_costs': 3600, 'integration_costs': 2500, 'maintenance_costs': 50000, 'num_R_and_D': 3, 'time_scale_project': 12, 'project_impact': 0.8}}
{'Project 1': {'scraping_valuable_data': 5898, 'data_annotation': 70200, 'project_manager': 80000, 'AI_R_and_D': 50000, 'infrastructure_costs': 3600, 'integration_costs': 2500, 'maintenance_costs': 50000, 'num_R_and_D': 2, 'time_scale_project': 12, 'project_impact': 0.9}, 'Project 2': {'scraping_valuable_data': 3000, 'data_annotation': 52900, 'project_manager': 90000, 'AI_R_and_D': 50000, 'infrastructure_costs': 2000, 'integration_costs': 3500, 'maintenance_costs': 50000, 'num_R_and_D': 3, 'time_scale_project': 6, 'project_impact': 0.5}, 'Project 3': {'scraping_valuable_data': 3245, 'data_annotation': 6000, 'project_manager': 70000, 'AI_R_and_D': 50000, 'infrastructure_costs': 3600, 'integration_costs': 2500, 'maintenance_costs': 50000, 'num_R_and_D': 2, 'time_scale_project': 18, 'project_impact': 0.4}, 'Prjoect 4': {'scraping_valuable_data': 9066, 'data_annotation': 82813, 'project_manager': 70000, 'AI_R_and_D': 50000, 'infrastructure_costs': 3600, 'integration_costs': 2500, 'maintenance_costs': 50000, 'num_R_and_D': 3, 'time_scale_project': 12, 'project_impact': 0.8}, 'Project 5': {'scraping_valuable_data': 6002, 'data_annotation': 68400, 'project_manager': 90000, 'AI_R_and_D': 50000, 'infrastructure_costs': 3600, 'integration_costs': 2500, 'maintenance_costs': 60000, 'num_R_and_D': 2, 'time_scale_project': 18, 'project_impact': 0.1}}
However, my desired output should look like this
{'Project 1': {'scraping_valuable_data': 5898, 'data_annotation': 70200, 'project_manager': 80000, 'AI_R_and_D': 50000, 'infrastructure_costs': 3600, 'integration_costs': 2500, 'maintenance_costs': 50000, 'num_R_and_D': 2, 'time_scale_project': 12, 'project_impact': 0.2},
'Project 2': {'scraping_valuable_data': 3000, 'data_annotation': 52900, 'project_manager': 90000, 'AI_R_and_D': 50000, 'infrastructure_costs': 2000, 'integration_costs': 3500, 'maintenance_costs': 50000, 'num_R_and_D': 3, 'time_scale_project': 6, 'project_impact': 0.5},.....}
CodePudding user response:
Your print is in the for loop.
for i, project in enumerate(project):
proj[project] = {
'scraping_valuable_data': scraping_valuable_data[i],
'data_annotation':data_annotation[i],
'project_manager':project_manager[i],
'AI_R_and_D':AI_R_and_D[i],
'infrastructure_costs':infrastructure_costs[i],
'integration_costs':integration_costs[i],
'maintenance_costs':maintenance_costs[i],
'num_R_and_D':num_R_and_D[i],
'time_scale_project':time_scale_project[i],
'project_impact':project_impact[i]}
print(proj)
CodePudding user response:
Try the below 1 liner. (TODO - add more lists)
project=["Project 1","Project 2","Project 3", "Prjoect 4", "Project 5"]
scraping_valuable_data = [5898,3000,3245,9066,6002]
data_annotation = [70200,52900,6000,82813,68400]
project_manager = [80000,90000,70000,70000,90000]
AI_R_and_D = [50000,50000,50000,50000,50000]
infrastructure_costs = [3600,2000,3600,3600,3600]
integration_costs = [2500,3500,2500,2500,2500]
maintenance_costs = [50000,50000,50000,50000,60000]
num_R_and_D = [2,3,2,3,2]
time_scale_project = [12,6,18,12,18]
project_impact = [0.9,0.5,0.4,0.8,0.1]
proj = {p: {'scraping_valuable': scraping, 'data_annotation': vd, 'project_manager': pm} for p,scraping,vd,pm in zip(project,scraping_valuable_data,data_annotation,project_manager)}
print(proj)
output
{'Project 1': {'scraping_valuable': 5898, 'data_annotation': 70200, 'project_manager': 80000}, 'Project 2': {'scraping_valuable': 3000, 'data_annotation': 52900, 'project_manager': 90000}, 'Project 3': {'scraping_valuable': 3245, 'data_annotation': 6000, 'project_manager': 70000}, 'Prjoect 4': {'scraping_valuable': 9066, 'data_annotation': 82813, 'project_manager': 70000}, 'Project 5': {'scraping_valuable': 6002, 'data_annotation': 68400, 'project_manager': 90000}}