Hash Maps Flashcards
What is the other name for hash maps in Python?
dictionaries
True or False: You can’t have duplicate keys in a hash map
True - each key has to be unique
How would you get the number of keys included in a hash map?
len(myMap)
How would you modify the value of the following key:
myMap = {“Alice”: 79}
myMap[“Alice”] = 80
How would you search for a value in a hash map?
print(“Alice” in myMap)
How would you initialize multiple values in a hash map?
myMap = {“Alice”: 90, “Bob”: 70}
How would we initialize a hash map using list comprehension?
myMap = {i: 2*i for i in range(3)}
Result would be {0: 0, 1: 2, 2: 4}
How can you loop through a hash map?
for key in myMap:
print(key, myMap[key])
How can we loop through a hash map and return just the values?
for val in myMap.values():
print(val)
How can we get both the keys and the values of a hash map using a loop?
for key, val in myMap.items()