Previous Lesson Current Lesson Next Lesson

Question 1

d = {"dog": 2, "cat": 3, "mouse": 5}

Curly braces and comma-delimited collection of key-value pairs. And done!

Question 2

Building off of our previous solution, we have:

d = {"dog": 2, "cat": 3, "mouse": 5}
print(len(d))

This will output:

3

Question 3

Building off of our previous solution, we have:

d = {"dog": 2, "cat": 3, "mouse": 5}

d["horse"] = 6
d["dog"] = 7

d.pop("mouse")

The new dictionary looks like this:

{'dog': 7, 'cat': 3, 'horse': 6}

Question 4

Building off of our previous solution, we have:

print(len(d))
print(d["dog"])

This will output:

3
7

There are 3 key-value pairs, and the associate value with "dog" is 7.