Dictionaries Flashcards

1
Q

In Python, what are dictionaries?

A

Dictionaries are mappings which are a collection of objects that are stored by a key and then an associated value.

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

Construct a dictionary with two key values.

A

my_dict = {‘key1’ : ‘value1’, ‘key2 : ‘value2’}

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

my_dict = {‘key1’:234, ‘key2: [12,23,46], ‘key3’:[‘item0’, ‘item1’ , ‘item2’]}
Call key3 and display the output

A

my_dict[‘key3’]
[‘item0’ , ‘item1’, ‘item2’]

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

my_dict = {‘key1’:chair’ , ‘key2’:’table’, ‘key3’:[13,34,72], ‘key4’: [‘car1’, ‘car2’, ‘car3’]}
- Call key4 from my_dict and then call index[1] from the return vaiue.

A

my_dict[‘key4’]
[‘car1’, ‘car2’, car3’]
my_dict[‘key4’][1]
‘car2’

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

my_dict = {‘key1’:chair’ , ‘key2’:’table’, ‘key3’:[13,34,72], ‘key4’: [‘car1’, ‘car2’, ‘car3’]}
- Call key4 from my_dict and then call index[1] in uppercase from the return vaiue.

A

my_dict[‘key4’]
[‘car1’, ‘car2’, car3’]
my_dict[‘key4’][1].upper()
‘CAR2’

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

create {‘animal’: ‘Dog’, ‘answer’ : 42} from the dictionary d

A

d = {}
d[‘animal’] = ‘Dog’
d[‘answer’] = 42
d
(rtn = {‘animal’: ‘Dog’, ‘answer’: 42}

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

car_colour = {}
car_colour[‘blue’] = ‘polo’
car_colour[‘answer’] = 1997
car_colour

A

{‘blue’ : ‘polo’, ‘answer’ : 1997}

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

d = {‘car’:{‘blue’ :{‘year’: ‘1997}}}
Grab the value.

A

d[‘car’][‘blue’][‘year’]
- 1997

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

what method is used to return a list of all keys?

A

.keys()

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

what method is used to grab all values?

A

.values()

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

what method is used to return tuples of all items?

A

.items(()

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