Python: Creating Dictionaries Flashcards

1
Q

What is a dictionary ?

A

an unordered set of key : value pairs

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

a dictionary begins and ends with what?

A

( { and } )

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

each item consist of a ? and a _?__

A

key and a value

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

We can have a list or a dictionary as a __?__ of an item in a dictionary, but we cannot use these data types as __?__ of the dictionary.

A

We can have a list or a dictionary as a VALUE of an item in a dictionary, but we cannot use these data types as KEYS of the dictionary.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Write the code to create an empty dictionary called animals_in_zoo

A

animals_in_zoo = {}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Add “zebras” to animals_in_zoo as a key with a value of 8.

A

animals_in_zoo[“zebras”] = 8

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

If we wanted to add multiple key : value pairs to a dictionary at once, we can use the __?__ method

A

.update() method

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Create a dictionary called drinks_to_caffeine by using a list comprehension that goes through the zipped_drinks list and turns each pair into a key:value item.

A

drinks_to_caffeine = {key: value for key, value in zipped_drinks}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

_?__ cannot be the keys of a dictionary, because they are mutable

A

Lists cannot be the keys of a dictionary

How well did you know this?
1
Not at all
2
3
4
5
Perfectly