'''
Created on Sep 26, 2016

@author: Susan
This example processes words from a file 
by creating a list of all the words. 
'''

    

def lengthLongestWord(words):
    maxSoFar = 0
    for w in words:
        if len(w) > maxSoFar:
            maxSoFar =  len(w)
    return maxSoFar

def LongestWord(words):
    maxSoFar = 0
    longword = ""
    for w in words:
        if len(w) > maxSoFar:
            maxSoFar =  len(w)
            longword = w
    return longword
  

def countWords(words):
    sum = 0
    for w in words:
        sum += 1
    return sum

def countWords2(words):
    return len(words)

if __name__ == '__main__':
    datafile = "romeo.txt"
    #datafile = "small.txt"
    f = open(datafile)
    bigString = f.read()
    allwords = bigString.split()
    print "Number of words in file"
    print countWords(allwords)
    print countWords2(allwords)
    print "length of longest word"
    print lengthLongestWord(allwords)
    print LongestWord(allwords)

    
