Example 1: Nested dictionary Python
IDs = ['emp1','emp2','emp3']
EmpInfo = [{'name': 'Bob', 'job': 'Mgr'},
{'name': 'Kim', 'job': 'Dev'},
{'name': 'Sam', 'job': 'Dev'}]
D = dict(zip(IDs, EmpInfo))
print(D)
Example 2: make nested dict from two dict
data = [
[14, 77766, [2, 2]],
[15, 77766, [1, 2]],
[70, 88866, [1, 5]],
[71, 88866, [2, 5]],
[72, 88866, [5, 5]],
[73, 88866, [4, 5]],
[74, 88866, [3, 5]],
[79, 99966, [1, 2]],
[80, 99966, [2, 2]],
]
c = {}
for key, id_, (value, _) in data:
c.setdefault(id_, {})[key] = value
print(c)
Example 3: how to nested dictonary that condition
people = {1: {'name': 'John', 'age': '27', 'sex': 'Male'},
2: {'name': 'Marie', 'age': '22', 'sex': 'Female'}}
people[3] = {}
people[1]['name'] = 'Luna'
people[1]['age'] = '24'
people[1]['sex'] = 'Female'
people[1]['married'] = 'No'
print(people[1])