"""
This program creates a list of vocabulary from a given text file.
"""


def vocab(filename):
    '''takes a filename as argument, returns the list that contains the
    vocabulary of that file.'''
    myString = readFile(filename)
    myWords = myString.split()
    reducedMyWords = noReplicates(myWords)
    return reducedMyWords

def readFile(filename):
    '''takes a filename as argument, returns a string that contains
    the first 10000 characters in that file.'''
    myFile = open('Z:/Windata/Desktop/' + filename) 
    # 'Z:/Windata/Desktop/' is an example of how it should actually look like. 
    # The file has to be in the same directory as this .py file
    myString = myFile.read()
    return myString[:10000]

def noReplicates(wordList):
    '''takes a list as argument, returns a list free of replicate items.
    slow implementation.'''
    result = []
    for word in wordList:
        if isElementOf(word, result):
            pass # You pass. Essentially you do nothing in this case
        else:
            result += [word] # This is another way to add elements to a list
    return result

def isElementOf(element,list):
    '''takes two arguments- the first argument is an element 
    and the second one is a list.
    Returns True if the element is a member of the list
    False otherwise.'''
    for item in list:
        if element == item:
            return True
    return False

# Two ways of iterating through a list
# The first one is considered the "iterating-by-index" way.
# It gives you extra powers!

wordList = ['steve jobs', 'apple', 'ipod', 'ipad', 'iphone']

print('New way of interating...')

for index in range(0,len(wordList)):
    if index == 0:
        print(wordList[index] + ' comes after nothing.')
    else:
        print(wordList[index] + ' comes after ' + wordList[index-1] + '.')

print('\nOld way...')

for word in wordList:
    print(word)


##########################################################################
#########################  ACTUAL HOMEWORK  ##############################
##########################################################################


def fastNoReplicates(inputList):
    '''takes a list as argument, returns a list free of replicate items.
    fast implementation. Make sure to test that this function works after you write it.
    Here is an example of how you can test it. Write the following outside of this function body:

    myList = ['the', 'blue', 'cat', 'just', 'ate', 'the', 'blue', 'fish']
    newList = fastNoReplicates(myList)
    print newList

    Now, the list should just be ['ate', 'blue', 'cat', 'fish', 'just', 'the'] (because the list first gets sorted)

    Write some of your own tests too!
    '''
    result = []
    inputList.sort() # Here inputList is sorted. Nothing is returned by sort() but inputList is changed

    #TODO


    return result   # dummy value to return



def cleanup(s):
    '''takes a string as argument, and returns a cleaned-up string,
    free of numbers and punctuations, all lowercase.'''
    result = s.lower()
    result = removeNumbers(result)
    result = removePunctuations(result)
    return result


def removeNumbers(s):
    '''takes a string as argument, and returns another string,
    replacing numbers with whitespaces.'''
    result =''
    for char in s:
        if(char=='0' or char=='1' or char=='2' or char=='3'
           or char=='4' or char=='5' or char=='6' or char=='7'
           or char=='8' or char=='9'):
            result += ' ' # Here you are adding a space to your result string
        else:
            result += char # Here you are adding the characters to your string
            
    return result
            

def removePunctuations(s):
    '''takes a string as argument, and returns another string,
    replacing punctuation marks with whitespaces.
    Here is an example of how you can test that your finished function works:

    myString = "Ishmael, you just had 23 fish sticks; and you want to eat 51 more? That is crazy!"
    newString = removePunctuations(myString)
    print newString

    newString should now be "Ishmael  you just had 23 fish sticks  and you want to eat 51 more  That is crazy"
    Write your own test cases as well.
    '''
    #TODO

    return s   # dummy value to return


def avgWord(filename, minLength):
    '''takes a filename and an integer as arguments, and returns
    the average length of the words in the text greater than minLength.
    An example test case:
    
    First, create a text file that says "My name is Joe." Save this as 'test1.txt' in the same directory as your Moby Dick text.
    Goal: Find the average length of the words in the text file for the words with more than 2 characters.
    Accomplish this by writing the following outside your function body:
	
	print avgWord('test1.txt', 3)
	
    This should give you 3.5, because the only words with more than 2 characters are 'name' and 'Joe'.
    Try your own tests as well!
    '''

    myWordList = vocab(filename)
    sumOfLengths = 0.
    numOfWords = len(myWordList)
    #TODO
    avg = 0
    #TODO
    return avg


