# Fake a dictionary to look up names, given phone numbers.
# We'll use a list as a pretend dictionary. The purpose is
# to show how a Python dictionary really works. 

# Here's a phonebook dictionary, which lets us look up
# numbers given names. This is the input. 
phoneBook = {}
phoneBook["Bob"] = 7584029
phoneBook["Lucy"] = 2206830
phoneBook["Morris"] = 6730056
print len(phoneBook)

# Pick a prime number, larger than the number of things
# I need to store.
listlen = 7

# Our fake dictionary will be a list of lists, called poser.
poser = []
# Fill it up with zeros to start with
for i in range(listlen):
    poser = poser+[0]

# Now add in each number-name pair as a list.  
# But where to put it in the list of lists? 
for name in phoneBook:
    number = phoneBook[name]
    # Calculate the index, based on the phone number
    # We use the remainder when dividing by the length of the list
    # This ensures that we get a valid index (between 0 and lenlist-1)
    index = number % listlen
    print name,"gets index",index
    poser[index] = [number,name]

# As we see, we end up scattering the pairs around in the list of lists
# in a somewhat arbitrary way. 
print poser

# Now to look up a number....
numStr = raw_input("Enter phone number: ")
number = int(numStr)
# We calculate the index, based on the number, in exactly the same way.
index = number % listlen
if poser[index] == 0:
    print "That number is not in the dictionary."
else:
    dataList = poser[index]
    name = dataList[1]
    print "That number belongs to",name

    



