ch 10 practice questions Flashcards

1
Q

What is printed in the following?

pokemon_name_n_type = {‘Squirtle’: ‘Water’, ‘Charmander’: ‘Fire’, ‘Bulbasaur’ : ‘Grass’}
print(‘Water’ in pokemon_name_n_type)

A

True

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

What will the following print?

word = ‘brontosaurus’
d = dict()
for c in word:
if c not in d:
d[c] = 1
else:
d[c] = d[c] + 1
print(d)

A

{‘b’: 1, ‘r’: 2, ‘o’: 2, ‘n’: 1, ‘t’: 1, ‘s’: 2, ‘a’: 1, ‘u’: 2}

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

what does the dictionary function .get() do?

A

takes a key and a default value. If the key appears in the dictionary, get returns the corresponding value; otherwise it returns the default value

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

What does the following print?

word = “incomprehensible”
d = dict()
for char in word:
if char not in d:
d[char] = 1
else:
d[char] = d[char] + 1
print(d.get(‘d’, 0))

A

0

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