# TelephoneBook   holds the data structure and maintenance functions
#  for a telephone book.

# The data structure is a dictionary of key,number pairs:
# Example:  book = {"Mary Smith":3453, "Jake Jones":2458}
book = {}   # the book starts empty

def printBook() :
    """printBook  prints the entire contents of the phone book"""
    keylist = book.keys()  # build list of all the keys
    keylist.sort()  # sorts the list alphabetically
    for k in keylist :  
        print k, ":", book[k]
    
def insert(name, number) :
    """addPerson  adds a new  name and number to the phone book,
       provided that the name is not already in the book.

       parameters: name - a string, the person's name
                   number - an int, the four-digit phone number
    """
    if  not(name in book) : 
        book[name] = number
    else :
        print "error: " + name + " is already in the book"


def lookup(name) :
    """lookup searches the phone book for name.

       parameter: name - a string, the person's name
       returns: the phone number, an int, for the person
         (if the name isn't in the book,  -1 is returned)
    """
    answer = -1
    if name in book :
        answer = book[name]
    return answer


def delete(name) :
    """delete removes the entry for  name  in the book.

       parameter: name - the name to be removed
    """
    if name in book :
       del book[name]