1IDs = ['emp1','emp2','emp3']
2
3EmpInfo = [{'name': 'Bob', 'job': 'Mgr'},
4 {'name': 'Kim', 'job': 'Dev'},
5 {'name': 'Sam', 'job': 'Dev'}]
6
7D = dict(zip(IDs, EmpInfo))
8
9print(D)
10# Prints {'emp1': {'name': 'Bob', 'job': 'Mgr'},
11# 'emp2': {'name': 'Kim', 'job': 'Dev'},
12# 'emp3': {'name': 'Sam', 'job': 'Dev'}}
1data = [
2 [14, 77766, [2, 2]],
3 [15, 77766, [1, 2]],
4 [70, 88866, [1, 5]],
5 [71, 88866, [2, 5]],
6 [72, 88866, [5, 5]],
7 [73, 88866, [4, 5]],
8 [74, 88866, [3, 5]],
9 [79, 99966, [1, 2]],
10 [80, 99966, [2, 2]],
11]
12
13c = {}
14for key, id_, (value, _) in data:
15 c.setdefault(id_, {})[key] = value
16print(c)
17
1family = { } # empty nested dictionary
2print("\n",family)
3
4family['member1'] = {} # adding child dictionary
5print("\n",family)
6
7
8family['member1']['name'] = 'Bob' # Adding elements one at a time
9family['member1']['age'] = 21 # Adding elements one at a time
10
11print("\n",family) # After adding member1 dictionary
12
13
14family['member2'] = {'name': 'Cara', 'age': 25} # Adding whole member2 dictionary
15
16print("\n",family)