Hash Maps Flashcards

1
Q

What is the other name for hash maps in Python?

A

dictionaries

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

True or False: You can’t have duplicate keys in a hash map

A

True - each key has to be unique

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

How would you get the number of keys included in a hash map?

A

len(myMap)

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

How would you modify the value of the following key:

myMap = {“Alice”: 79}

A

myMap[“Alice”] = 80

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

How would you search for a value in a hash map?

A

print(“Alice” in myMap)

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

How would you initialize multiple values in a hash map?

A

myMap = {“Alice”: 90, “Bob”: 70}

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

How would we initialize a hash map using list comprehension?

A

myMap = {i: 2*i for i in range(3)}

Result would be {0: 0, 1: 2, 2: 4}

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

How can you loop through a hash map?

A

for key in myMap:
print(key, myMap[key])

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

How can we loop through a hash map and return just the values?

A

for val in myMap.values():
print(val)

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

How can we get both the keys and the values of a hash map using a loop?

A

for key, val in myMap.items()

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