Dictionaries

Made up of values with a unique key for each value.

super_villains = {
    'Fiddler': 'Isaac Bowin',
    'Captain Cold': 'Leonard Snart',
    'Weather Wizard': 'Mark Mardon',
    'Mirror Master': 'Sam Scudder',
    'Pied Piper': 'Thomas Peterson'
}
1
2
3
4
5
6
7

We can access and rewrite values almost like with list. The only difference is that we need to pass key instead of index

super_villains['Captain Cold']

super_villains['Pied Piper'] = 'Hartley Rathaway'
1
2
3

Basic operations

Delete an entry

del super_villains['Fiddler'] # Delete an entry
# >>>
1
2

Print the number of items in the dictionary

len(super_villains)
# >>>
1
2

Get a list of dictionary keys

super_villains.keys()
# >>>
1
2

Get a list of dictionary values

super_villains.values()
# >>>
1
2

We can merge several dicts like so

dict2 = {**dict3, **dict2}
# >>>
1
2