ch 10 practice questions Flashcards
What is printed in the following?
pokemon_name_n_type = {‘Squirtle’: ‘Water’, ‘Charmander’: ‘Fire’, ‘Bulbasaur’ : ‘Grass’}
print(‘Water’ in pokemon_name_n_type)
True
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)
{‘b’: 1, ‘r’: 2, ‘o’: 2, ‘n’: 1, ‘t’: 1, ‘s’: 2, ‘a’: 1, ‘u’: 2}
what does the dictionary function .get() do?
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
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))
0