# Ryan Martin
# macid: abcd123
# student number: #######
# July 12, 2011
#
# This is a solution for Marked Assignment 2 (Lab 05) on Thursday.

def main():

    print """\

This program is a solution to Marked Assignment 2 (Lab 05) on Thursday.

"""

    #INPUTS
    
    FName = raw_input("Enter the name of the input file containing word-definition pairs: ")
    F = open(FName, "r")
    wordDefList = F.readlines()
    F.close()

    #strip() takes of unwanted whitespace
    word = raw_input("Enter the word to look up in the dictionary: ").strip()
    print 

    #PROCESSING
    wordList = [] #Or: wordList = list()
    defList = [] 
    for line in wordDefList: 
        pair = line.split(":")
        wordList.append(pair[0].strip()) 
        defList.append(pair[1].strip())

    '''Alternative method (one of many):
    
    listSize = len(wordDefList)
    wordList = range(listSize) #Gets a list of the same size as inputList
    defList = range(listSize)
    for i in range(listSize):
        pair = wordDefList[i].split(":")
        wordList[i] = pair[0].strip()
        defList[i] = pair[1].strip()
    
    '''

    wordIndex = wordList.index(word)
    definition = defList[wordIndex]

    #OUTPUT
    
    print "The requested definition =", definition
    print ""

main()

'''
Design Question

Since the index() method will return an error if the word
does not exist in the list, the program should first check 
the list of words and see if the requested word exists
before attemping to retrieve the index. We can use 
the count() method to see if there more then zero
instances of the word in the list, and exit with a warning
otherwise (rather then crashing). 

Alternatively, we can also catch the error itself rather
then check the list for the word, and exit gracefully
that way. We will learn about error handling later in 
the course.

Testing Report

REPORT

Test: 1
Input: word: Engineering
******************Word-Definition List in F********************
AwesomeSauce:When awesome is just not good enough.
Recursion:See *Recursion.*
Erinaceous:Like or similar to a hedgehog.
ComputerScience:The science of computing.
Engineering:The secret to success.

Expected Output: [The secret to success.]
Actual Output: [The secret to success]
Result:Pass
'''