100 Days of Code - Dictionaries, Nesting (Day9)

Dictionary

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29

# definition a dictionary
{key: value}

dictionary = {
"key1": "value1",
"key2": "value2",
"key3": "value3"
}

# retrieve data from dictionary
dictionary["key1"] # value1
dictionary["key2"] # value2

# add data to dictionary
dictionary["key4"] = "value4"

# wipe an existing dictionary
dictionary = {}

# Loop through a dicrionary
for key in dictionary:
print(key) # will print key

# Nesting Lists and Dictionaries
{
key: [List],
key1: {Dict}
}