Learn how to

Access a dict

For exemple

teacher_subject = {'Ben':'English','Maria':'Math','Steve':'Science'}

To get the keys from a dictionary

teacher_subject.keys()

Result

dict_keys(['Ben', 'Maria', 'Steve'])

To get the values from a dictionary

teacher_subject.values()

Result

dict_values(['English', 'Math', 'Science'])

To get the pair of keys and values from a dictionary

teacher_subject.items()

Result

dict_items([('Ben', 'English'), ('Maria', 'Math'), ('Steve', 'Science')])

Switch the keys and values

subject_teacher = {y:x for x,y in teacher_subject.items()}
subject_teacher

Returns

{'English': 'Ben', 'Math': 'Maria', 'Science': 'Steve'}

Merge two dict

dict1 = { 'a': 1, 'b': 2 }
dict2 = { 'b': 3, 'c': 4 }
merged = { **dict1, **dict2 }
print (merged)
# {'a': 1, 'b': 3, 'c': 4}