In [1]:
class Node:

    def __init__(self, name, phone, address, next):
        self._name = name
        self._phone = phone
        self._address = address
        self._next = next

    def __str__(self):
        return "("+self._name+","+self._phone+","+self._address+")"
In [ ]:
class ContactsLL:

    # singly linked list of contacts with header node, non-circular, unsorted

    def __init__(self):
        self._head = Node("","","",None)
        self._size = 0

    def find(self,name):
        p = self._head
        found = False
        while p._next != None and not found:
            if p._next._name == name:
                found = True
            else:
                p = p._next
        if found:
            #return (p._next._name,p._next._phone,p._next._address)
            return p
        else:
            return None
            

    def insert(self,contact):
        if self.find(contact[0]) != None:
            return None
        else: # insert in first position because we have UNSORTED
            p = Node(contact[0],contact[1],contact[2],self._head._next)
            self._head._next = p
            self._size = self._size + 1
            return True

    def delete(self,name):
        # do a find; if found the p will be the pointer to the previous node!

    def update(self,contact):
        # do a find; if found then update object p 
        
    def size(self):
        return self._size

    def __str__(self):
        p = self._head
        result = "\n"
        while p._next != None:
            result = result + str(p._next)+"\n"
            p = p._next
        return result+"\n"
In [ ]:
class ContactsHT:
    NUM_BUCKETS = 100
    # hash table for contacts

    def __init__(self):
        self._hashtable = [Node("","","",None) for i in range(ContactsHT.NUM_BUCKETS)]
        self._size = 0

    @classmethod
    def myhash(cls,name):
        sum = 0
        for x in name:
            sum = sum + ord(x)
        return sum%ContactsHT.NUM_BUCKETS

    def find(self,name):
        bnum = ContactsHT.myhash(name)
        p = self._hashtable[bnum]
        found = False
        while p._next != None and not found:
            if p._next._name == name:
                found = True
            else:
                p = p._next
        if found:
            #return (p._next._name,p._next._phone,p._next._address)
            return p
        else:
            return None

    def insert(self,contact):
 
    def delete(self,name):

    def update(self,contact):

    def size(self):
        return self._size

    def __str__(self):
        result = "\n"
        for hindex in range(ContactsHT.NUM_BUCKETS):
            p = self._hashtable[hindex]
            while p._next != None:
                result = result + str(p._next)+"\n"
                p = p._next
        return result+"\n"
In [4]:
ord('Z')
Out[4]:
90
In [9]:
NUM_BUCKETS = 100
sum = 0
for x in "BOES":
    sum = sum + ord(x)
print(sum)
print(sum%NUM_BUCKETS)
297
97
In [ ]: