mymap = {}
mymap["alice"] = 88
len(mymap) # 1, number of keys in the hashmap
# we can also modify the value of the key
mymap['alice'] = 10
# We can also search for a key in a hashmap in constant time
print("alice" in mymap) # True
mymap.pop("alice")
mymap = { "alice": 90, "bob": 70 }Dict comprehension
Useful for graph problems and building adjacency list
mymap = { i: 2*i for i in range(3) }i is the key and the value is 2*i
Looping through a hashmap
mymap = { "alice": 90, "bob": 70 }
for key in mymap:
print(key, mymap[key])
for val in mymap.values():
print(val)
for key, val, in mymap.items():
print(key, val)