In [ ]:
%%HTML
<style>
.container { width:100% } 
</style>

A Trivial Implementation of the ADT Map

The following trivial implementation of the ADT Map is based on Pythons dictionaries.


In [ ]:
class Map:
    def __init__(self):
        self.mDictionary = {}
    
    def find(self, k):
        return self.mDictionary.get(k, None)
    
    def insert(self, k, v):
        self.mDictionary[k] = v
        
    def delete(self, k):
        del self.mDictionary[k]
        
    def __str__(self):
        return str(self.mDictionary)

In [ ]:
m = Map()
m.insert('a', 1)
m.insert('b', 2)
m.insert('c', 3)
print(m)

In [ ]:
m.find('a')

In [ ]:
m

In [ ]:
Map.__repr__ = Map.__str__

In [ ]:
m.delete('b')
m

In [ ]:
m.insert('a', 42)

In [ ]:
m

In [ ]: